如何运行selft包含的.NET Core测试?

Thi*_*oIt 2 mstest self-contained .net-core

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

dotnet test --logger "trx;LogFileName=Result.trx" --settings tests.runsettings
Run Code Online (Sandbox Code Playgroud)

我还可以使用以下方法构建一个自包含的应用程序:

dotnet publish -c Release -f netcoreapp2.1 --force --self-contained --runtime win-x64 
Run Code Online (Sandbox Code Playgroud)

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

呼唤

dotnet test .\ProjectName.dll --logger "trx;LogFileName=Result.trx" --settings tests.runsettings
Run Code Online (Sandbox Code Playgroud)

出现“错误MSB4025:无法加载项目文件”。

关于如何运行此自包含MSTest-Project的任何提示?

MUG*_*G4N 5

您使用了错误的工具:

?  ~ dotnet --help
  test             Runs unit tests using the test runner specified in the project.
  vstest           Runs Microsoft Test Execution Command Line Tool.
Run Code Online (Sandbox Code Playgroud)

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

dotnet publish -o outputdir
dotnet vstest outputdir/your.dll
Run Code Online (Sandbox Code Playgroud)