在ASP.NET Core项目中运行NUnit测试需要添加NUnit Test Adapter和dotnet-test-nunit NuGet包,同时还要在.csproj文件中添加NUnit引用。以下是示例代码:
在NuGet包管理器中添加NUnit Test Adapter和dotnet-test-nunit NuGet包。
在.csproj文件中添加以下NUnit引用:
using NUnit.Framework;
namespace Sample.Tests
{
[TestFixture]
public class SampleTests
{
[Test]
public void TestMethod()
{
// Test code
Assert.AreEqual(2, 1+1);
}
}
}