Nunit: 无法加载文件或程序集“nunit.framework”

创建于 2018-02-14  ·  12评论  ·  资料来源: nunit/nunit

你好,我用dotnet nunit创建了一个新项目,当我尝试通过 Unit.ConsoleRunner.3.8.0 执行我的测试时收到这个错误。

点网 SDK 2.1.4 版

显示错误的示例存储库: https :

运行 ./build.ps1 来执行蛋糕文件。 执行此操作后,它将从 NuGet 下载 Unit.ConsoleRunner.3.8.0。 因此,在您运行它或下载 nuget 包之后,您可以跳过蛋糕业务,如果您愿意,只需在 PowerShell 中运行它:

.\tools\NUnit.ConsoleRunner.3.8.0\tools\nunit3-console.exe .\tests\Demo.Tests\bin\Release\netcoreapp2.0\Demo.Tests.dll

question

最有用的评论

我同意顺便说一句,很遗憾我们在 .NET Core 2.0 上还没有功能齐全的 NUnit.Console。 一旦我完成了当前的 PR,如果没有人打败我,我就会朝着那个方向前进。

所有12条评论

这是因为,与 .NET Framework 项目不同,.NET Core 项目没有将其依赖项(例如 nunit.framework.dll)复制到构建时的bin\{configuration}\{tfm}文件夹中。 您需要运行dotnet publish 。 对于 Cake,那就是DotNetCorePublish或者看看 NUnit 做了什么。 然后对bin\{configuration}\{tfm}\publish包含依赖项的程序集运行测试。

dotnet test在将\publish路径传递给dotnet vstest之前为您完成所有这些发布。
dotnet vstest和 NUnit Console 都在程序集上运行,而不是在项目上运行,因此要求您首先发布,就像您编写自执行测试一样。

Ahhhhhh 这真的很有启发性和帮助,非常感谢。 如果您查看 cake 上的示例,它们会清楚地显示导航到 bin 目录以执行测试: https :

希望遇到此问题的任何其他人都会看到这一点并节省一些时间。

在我走得太快之前:NUnit.ConsoleRunner 尚未在 .NET Core 上运行。 NUnitLite 可以,尽管这是运行 NUnit 测试的最简单方法: https :

示例: https :

@jnm2你的例子会产生测试结果吗? 从您发布的维基:

dotnet test 目前不支持将命令行选项传递给测试适配器,因此 NUnit 还不能生成 TestResults.xml。

这是我上次看的情况:

https://github.com/jnm2/Cake.SqlServer/blob/ed6093e268114ef640851414e64aabec49d284e8/build.cake#L114 -L134

try
{
    DotNetCoreTest("src/Tests/Tests.csproj", new DotNetCoreTestSettings
    {
        Configuration = configuration,
        NoBuild = true,
        Logger = "trx",
        ArgumentCustomization = a => a.AppendSwitchQuoted("--results-directory", tempDirectory)
    });
}
finally
{
    if (parameters.IsRunningOnAppVeyor)
    {
        // dotnet test cannot do more than one target framework per TRX file
        // AppVeyor seems to ignore all but the first TRX upload– perhaps because the test names are identical
        // https://github.com/Microsoft/vstest/issues/880#issuecomment-341912021
        foreach (var testResultsFile in GetFiles(tempDirectory + "/**/*.trx"))
            AppVeyor.UploadTestResults(testResultsFile, AppVeyorTestResultsType.MSTest);
    }
}

我同意顺便说一句,很遗憾我们在 .NET Core 2.0 上还没有功能齐全的 NUnit.Console。 一旦我完成了当前的 PR,如果没有人打败我,我就会朝着那个方向前进。

你好,有任何更新吗?

@orihomie这是一个封闭的问题。 我们是要问一个不同的吗?

@CharliePoole不,当我尝试通过 *\NUnit.Console-3.6.1\nunit3-console.exe 启动 .netcore 测试时,我刚刚在我的构建计划中遇到了这个问题,并且遇到了异常,导致我在这里

@orihomie有关通过控制台运行 .Net Core 测试的问题的跟进,请关注 nunit/nunit-console#478

此页面是否有帮助?
0 / 5 - 0 等级