Lib
Class1
and change the code to:using System;
namespace Lib
{
public class Class1
{
public string SayHello() => "Hello!";
}
}
.NET Standard libraries are tested with unit test projects of type .NET Framework or .NET Core projects. In this tutorial you will use a .NET Core project
Lib.Tests
Note: you can also add a .NET Core unit test project in Visual Studio. This will add the nuget packages automatically. For this tutorial, I think it is useful to show that a unit test project is a regular class library plus some added packages
Lib.Tests
to Lib
.Class1
and change the code to:using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace Lib.Tests
{
[TestClass]
public class TestClass1
{
[TestMethod]
public void Test1()
{
var cl = new Class1();
Assert.AreEqual(cl.SayHello(), "Hell!");
}
}
}
The test will fail:
Assert.AreEqual(cl.SayHello(), "Hell!");
to
Assert.AreEqual(cl.SayHello(), "Hello!");
This time the test should succeed: