.NET 6环境下Linux无需Mono直接运行nunit3-console可行吗?
问题解答
关于NUnit.ConsoleRunner 3.15.2是否依赖Mono
NUnit.ConsoleRunner 3.15.2完全支持.NET 6,自身无需依赖Mono即可运行,同时也能直接执行.NET 6的测试程序集,你弃用Mono的目标是可以实现的。
Linux上运行nunit3-console的报错解决
你遇到的报错是因为Windows和Linux的可执行文件格式不兼容:
.exe是Windows平台的可执行文件,Linux系统无法直接执行,因此会提示“cannot execute binary file”。- 找不到
nunit3-console文件,是因为当前的NUnit.ConsoleRunner包可能仅包含Windows版本文件,或者Linux版本的可执行文件在子目录(比如net6.0文件夹)中。
正确运行方式
- 确认NUnit.ConsoleRunner包包含跨平台文件,建议通过NuGet安装,Linux版本的可执行文件或dll通常在
tools/net6.0路径下。 - 在Linux下选择以下两种方式之一运行:
- 通过dotnet执行dll文件:
dotnet /trunk/Tools/Build/NUnit3/NUnit.ConsoleRunner.3.15.2/tools/net6.0/nunit3-console.dll --noheader --where:"cat == LongRunning" MyAssembly.Tests.dll --explore - 直接运行Linux可执行文件(若存在):
/trunk/Tools/Build/NUnit3/NUnit.ConsoleRunner.3.15.2/tools/net6.0/nunit3-console --noheader --where:"cat == LongRunning" MyAssembly.Tests.dll --explore
- 通过dotnet执行dll文件:
补充:dotnet test无法列出测试的解决
如果想用dotnet test列出测试,可直接执行:
dotnet test --list-tests
若仍无法正常显示,检查测试项目是否正确引用了NUnit3TestAdapter包,该适配器是让dotnet test识别NUnit测试的必要组件。
内容的提问来源于stack exchange,提问作者Kurt
相关产品推荐
相关产品推荐

