我创建了一个新的ASP.net Core v2.2项目,并添加了一个NUnit测试项目。当我运行该项目时,它会使用dotnet Core v2.2正确启动。但是,当我运行测试时,收到以下消息,并且测试错误(以在使用dotnet run
运行时它们不会出错的方式)。基于为v2.2构建和在v1中运行之间的不匹配,我认为它们已连接。
我不确定如何强制使用v2.2运行测试?
测试运行前的消息:
Test run will use DLL(s) built for framework .NETCoreApp,Version=v1.0 and platform X64. Following DLL(s) do not match framework/platform settings.
NUnitTest.dll is built for Framework 2.2 and Platform AnyCPU.
测试失败消息:
System.IO.FileNotFoundException : Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Formatters.Json, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
这是我尝试运行的测试代码:
using NUnit.Framework;
using API.Models;
using System.Threading.Tasks;
using System;
using System.Diagnostics;
namespace Tests
{
public class Tests
{
[SetUp]
public void Setup()
{
}
[Test]
public async Task Test1()
{
var credentials = new Credentials();
credentials.setAttributes("publicToken", "refreshTokenSample", 2000);
var token = await credentials.GetToken();
Assert.Equals("publicToken", token);
}
}
}
复制步骤:
Test run will use DLL(s) built for framework .NETCoreApp,Version=v1.0 and platform X86. Following DLL(s) do not match framework/platform settings.
NUnitTestProject1.dll is built for Framework 2.2 and Platform AnyCPU.