[{"data":1,"prerenderedAt":247},["ShallowReactive",2],{"tag-testing":3},{"tag":4,"articles":24},{"id":5,"title":6,"body":7,"description":14,"extension":15,"img":16,"meta":17,"name":18,"navigation":19,"path":20,"seo":21,"stem":22,"__hash__":23},"tags\u002Ftags\u002Ftesting.md","Testing",{"type":8,"value":9,"toc":10},"minimark",[],{"title":11,"searchDepth":12,"depth":12,"links":13},"",2,[],"A unit test is a way of testing a unit - the smallest piece of code that can be logically isolated in a system. In most programming languages, that is a function, a subroutine, a method or property. The isolated part of the definition is important.","md","https:\u002F\u002Fimages.unsplash.com\u002Fphoto-1598313183973-4effcded8d5e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=675&q=80",{},"testing",true,"\u002Ftags\u002Ftesting",{"description":14},"tags\u002Ftesting","Ff_w7mHDaTR4ynXul-ykC3R1NTVsYfPGk3aJjyr-GFM",[25],{"id":26,"title":27,"author":28,"body":29,"createdAt":238,"description":239,"extension":15,"img":115,"meta":240,"navigation":19,"path":241,"seo":242,"stem":243,"tags":244,"updatedAt":238,"__hash__":246},"articles\u002Farticles\u002Fxunit-what-is-it-and-why-another-unit-testing-framework.md","xUnit–what is it and why another unit testing framework",null,{"type":8,"value":30,"toc":236},[31,39,75,78,82,198,201,215,218],[32,33,34,35,38],"p",{},"Special thank you for Channel 9 and @skimedic for sharing his unit testing knowledge.",[36,37],"br",{},"\nXUnit leverage some of the new features to help developers write cleaner test, as tests should be kept clean and treated as first-class citizens.",[40,41,42,46,49,61,64],"ul",{},[43,44,45],"li",{},"NUnit was not fully compatible with .NET Core 2 at the time",[43,47,48],{},"xUnit is aimed at improving test isolation and trying to codify a set of rules to establish a testing standard.",[43,50,51,52,56,57,60],{},"xUnit ",[53,54,55],"span",{},"Fact"," and ",[53,58,59],{},"Theory"," attributes are extensible, so you can implement your own testing functionality.xUnit doesn’t use Test Lists and .vsmdi files to keep track of your tests.",[43,62,63],{},"Microsoft is using xUnit internally, one of its creators is from Microsoft. xUnit was also created by one of the original authors of NUnit.",[43,65,66,67,71],{},"Side-by-side Performance Comparison of testing frameworks can be found here ",[68,69],"a",{"title":70,"href":70},"https:\u002F\u002Fblogs.msdn.microsoft.com\u002Fvisualstudio\u002F2017\u002F11\u002F16\u002Ftest-experience-improvements\u002F",[68,72,70],{"href":70,"rel":73},[74],"nofollow",[32,76,77],{},"Where to get it and how to add it to your projects (2 ways)",[79,80,81],"ol",{},"  \n* Use Nuget to add xunit as well as the runner  \n* Add New Project – .NET Core xUnit Test Project  \n",[40,83,84,87,93,96,101,104,119,122,125,137,140,143,146,153,156,168,171,181,184,187],{},[43,85,86],{},"It does work with live unit testing",[43,88,89,90,92],{},"Add ",[53,91,55],{}," attribute on a method to mark it as a test",[43,94,95],{},"Use Theory and InlineData as mechanism to pass data into the test",[43,97,98,100],{},[53,99,59],{}," attribute to mark a method as a test and setup incoming parameters (2 approaches InlineData and MemberData)",[43,102,103],{},"[InlineData(1,2,3)",[43,105,106,107],{},"approach to pass data into the test method (add additional InlineData attributes for multiple runs of same test)\n",[68,108,110],{"href":109},"\u002Farticles\u002Fimages\u002FSNAGHTML2e5cfd1e_636767597902517481.png",[111,112],"img",{"style":113,"title":114,"src":115,"alt":114,"width":116,"height":117,"border":118},"border: 0px currentcolor; display: inline; background-image: none;","SNAGHTML2e5cfd1e","\u002Farticles\u002Fimages\u002FSNAGHTML2e5cfd1e_thumb_636767597903473559.png",487,209,0,[43,120,121],{},"MemberData(nameof(IEnumerable\u003Cobject>",[43,123,124],{},"In the example below we are using a method to return data to be used (however this method could also read data from other files such as text or excel to be returned)",[43,126,127,128],{},"approach to pass data into the test method\n",[68,129,131],{"href":130},"\u002Farticles\u002Fimages\u002FSNAGHTML2e5bc0f5_636767597904435811.png",[111,132],{"style":113,"title":133,"src":134,"alt":133,"width":135,"height":136,"border":118},"SNAGHTML2e5bc0f5","\u002Farticles\u002Fimages\u002FSNAGHTML2e5bc0f5_thumb_636767597905425086.png",484,226,[43,138,139],{},"xUnit runs it’s tests in parallel to take advantage of today’s processors",[43,141,142],{},"tests within one class are run serial",[43,144,145],{},"tests in multiple classes are run parallel",[43,147,148,149,152],{},"can be disabled by creating a test collection (add attribute ",[53,150,151],{},"Collection({name})",", and all within the same collection will be run serial",[43,154,155],{},"in order to test that an exception is thrown",[43,157,158,159],{},"Assert.Throws\u003CInvalidOperationException>(() => ThrowAnError());\n",[68,160,162],{"href":161},"\u002Farticles\u002Fimages\u002Fimage_636767597907208471.png",[111,163],{"style":113,"title":164,"src":165,"alt":164,"width":166,"height":167,"border":118},"image","\u002Farticles\u002Fimages\u002Fimage_thumb_636767597908147368.png",452,301,[43,169,170],{},"Setup\u002FTeardown",[43,172,173,174,56,177,180],{},"There are no ",[53,175,176],{},"Setup",[53,178,179],{},"Teardown"," attributes, this is done using the test class’ constructor and an IDisposable. This encourages developers to write cleaner tests.",[43,182,183],{},"use constructor in place of Setup attributes to prepare tests",[43,185,186],{},"now use IDisposable to replace teardown i.e. public class ATestClass : IDisposable\npublic void Dispose() {\n   \u002F\u002Fsomething here to clean up\n}",[43,188,189,190],{},"for input\u002Foutput there exists ITestOutputHelper as shown below to output log\n",[68,191,193],{"href":192},"\u002Farticles\u002Fimages\u002Fimage_636767597909423747.png",[111,194],{"style":113,"title":164,"src":195,"alt":164,"width":196,"height":197,"border":118},"\u002Farticles\u002Fimages\u002Fimage_thumb_636767597910292790.png",447,240,[32,199,200],{},"Notes",[40,202,203,206],{},[43,204,205],{},"Works in .net core and .net framework",[43,207,208,209,212],{},"TODO: Read up on Live Unit Testing ",[68,210],{"title":211,"href":211},"https:\u002F\u002Fdocs.microsoft.com\u002Fen-us\u002Fvisualstudio\u002Ftest\u002Flive-unit-testing?view=vs-2017",[68,213,211],{"href":211,"rel":214},[74],[32,216,217],{},"References:",[219,220,221,222,225,226,229,230,225,233],"blockquote",{},"  \n",[68,223,224],{"title":224,"href":224},"https:\u002F\u002Fxunit.github.io\u002Fdocs\u002Fwhy-did-we-build-xunit-1.0.html"," \n",[68,227,228],{"title":228,"href":228},"https:\u002F\u002Fdev.to\u002Fhatsrumandcode\u002Fnet-core-2-why-xunit-and-not-nunit-or-mstest--aei","   \n",[68,231,232],{"title":232,"href":232},"https:\u002F\u002Fchannel9.msdn.com\u002FShows\u002FVisual-Studio-Toolbox\u002FUnit-Testing-xUnit",[68,234,235],{"title":235,"href":235},"https:\u002F\u002Fxunit.github.io\u002F",{"title":11,"searchDepth":12,"depth":12,"links":237},[],"2018-11-02T12:49:51.111Z","Primarily XUnit leverages some new features to help developers write cleaner test, as tests should be kept clean and treated as first-class citizens.",{},"\u002Farticles\u002Fxunit-what-is-it-and-why-another-unit-testing-framework",{"title":27,"description":239},"articles\u002Fxunit-what-is-it-and-why-another-unit-testing-framework",[245,18],"netcore","Xa57WSBlnynbn4MUPddzdtkn0rAmRbojbJ2tqgZD33w",1781574760510]