XUnit- Getting started

xUnit.net is a free, open source, community-focused unit testing tool for the .NET Framework.Written by the original inventor of NUnit v2, xUnit.net is the latest technology for unit testing C#, F#, VB.NET and other .NET languages. xUnit.net works with ReSharper, CodeRush, TestDriven.NET and Xamarin
So now, without wasting much time let's get started with a simple test using XUnit.

1) Visual Studio > File > New > create a project (say XunitPractise)
2) Create a class (TestSet1)
3) Manage Nuget Packages For Solution >
    a) Add XUnit
    b) Add xunit.runner.visualstudio (enables you to run tests from Visual Studio)
4) The test should look like this

5) [Fact]: You may have wondered why your first unit tests use an attribute named [Fact] rather than one with a more traditional name like Test. xUnit.net includes support for two different major types of unit tests: facts and theories. When describing the difference between facts and theories, we like to say:
Facts are tests which are always true. They test invariant conditions.
Theories are tests which are only true for a particular set of data.

A good example of this testing numeric algorithms. Let's say you want to test an algorithm which determines whether a number is equal to 2. If you're writing the positive-side tests (providing numbers other than 2), then the test would fail, and not because the test or algorithm is wrong.

OUTPUT: Build the solution and run the tests from Test Explorer




Source


Comments

Popular Posts