Posts

Showing posts from March, 2019

How to unit test a .NET Core project using xUnit

Image
Basically the same instructions as given in the Microsoft site , which I attempt to make yet simpler for the beginner to get started. Another useful link: https://xunit.net/docs/getting-started/netfx/visual-studio#write-first-tests Step 1: Create a directory for the test project Create a new directory for the test project. Navigate to that directory Create a new solution using the command: dotnet new sln Step 2: Create a new class library In the current directory create a new folder called Example. Navigate to the directory Example and run the command to create a new class library: dotnet new classlib. Step 3: Create an example test class Rename Class1.cs to Example.cs. Update the code in Example.cs to produce a function to test if an integer is even: [code language="csharp"] using System; namespace Example { public class ExampleService { public bool IsEven(int val) { return val % 2 == 0; } }...