.NET

Unit testing C# with MSTest and .NET Core Part 1 – Create the source project

Writing Unit Tests is fun! So let’s follow this and write Unit Testing with MSTest.

First create the folder structure for the project and inside create the solution file for the class library and the test project.

mkdir unit-testing-using-mstest
cd .\unit-testing-using-mstest\
dotnet new sln
mkdir PrimeService

Create a the new source project which is a class library and rename the Class1.cs to PrimeService.cs

dotnet new classlib
Rename-Item .\Class1.cs PrimeService.cs

Go back to the previous folder and add the project to the solution file.

dotnet sln add .\PrimeService\PrimeService.csproj

Now launch visual studio by running the .sln from the command line.

Edit the code in the class PrimeService as defined in the tutorial by creating a new namespace and class name.

namespace Prime.Services
{
    public class PrimeService
    {
        public bool IsPrime(int candidate)
        {
            throw new NotImplementedException("Please create a test first.");
        }
    }
}

Great work! In the next post we’ll create the test project!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: