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

How to run self-contained .NET Core tests?

我有一个 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 项目有什么提示吗?

dotnet 测试现在 (2022) 接受 .dll 文件来执行测试。

您使用了错误的工具:

➜  ~ 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