如何运行独立的 .NET Core 测试?



我有一个 MSTest 项目,在执行时工作正常:

dotnet test --logger "trx;LogFileName=Result.trx" --settings tests.runsettings

我还能够通过以下方式构建一个独立的应用程序:

dotnet publish -c Release -f netcoreapp2.1 --force --self-contained --runtime win-x64 

但是我不知道如何从生成的输出运行测试。

dotnet test .ProjectName.dll --logger "trx;LogFileName=Result.trx" --settings tests.runsettings

失败,并显示以下消息:

error MSB4025: The project file could not be loaded.

关于如何运行这个自我保护的 MSTest-Project 的任何提示?

dotnet test now (2022( 的最新版本(此处需要详细信息(接受.dll文件来执行测试执行。有关详细信息,请参阅官方 dotnet 测试文档。

对于早期版本...

您使用了错误的工具:

➜  ~ dotnet --help
test             Runs unit tests using the test runner specified in the project.
vstest           Runs Microsoft Test Execution Command Line Tool.

dotnet test是用于运行给定项目中定义的单元测试的工具。如果您尝试从已发布的 dll 中运行测试,您应该dotnet vstest命令。你这样做是这样的:

dotnet publish -o outputdir
dotnet vstest outputdir/your.dll

最新更新