我按照这些说明创建了全新的项目,成功地完成了这项工作......
https://learn.microsoft.com/en-us/dotnet/articles/core/testing/using-mstest-on-windows
似乎 MSTest dotnet 核心项目需要创建为控制台应用程序才能工作..?
为了帮助所有其他人,这是我最终得到的project.json。
{
"version": "1.0.0-*",
"testRunner": "mstest",
"dependencies": {
"dotnet-test-mstest": "1.1.1-preview",
"MyLibrary": {
"target": "project"
},
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
},
"MSTest.TestFramework": "1.0.4-preview",
"NSubstitute": "2.0.0-rc"
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
我似乎在做两件不同的关键事情。首先,我的关键依赖是以前......
"NETStandard.Library": "1.6.0"
而在新的project.json中它是
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
(在原始的project.json中,它作为子依赖项放置在文件的框架部分中)。
另一个位于“newtcoreapp1.0”下的导入部分。在原始的project.json中,我使用了它本身,而工作的则导入了dnxcore50(尽管我仍然不相信这实际上是正确的)。
MSTest.TestFramework 的 1.0.5 预览版似乎存在错误 - 我最终更改了早期版本的版本。在 1.0.5 中,测试会加载,但每个测试都会因错误而失败......
无法从程序集“Microsoft.VisualStudio.TestPlatform.TestFramework”加载类型“LogMessageHandler”
我四处寻找可以将其作为错误提交的地方,但还没有运气。如果有人发现它有同样的问题并且知道在哪里记录它,请告诉我,我会'+1'它。
为了完整起见,这里有一个适用于 NUnit 的 project.json 文件(尽管它是 NUnit 3 并且读取它的输出文件(在撰写本文时)是 VSTS 上的一个问题...
{
"dependencies": {
"MyLibrary": {
"target": "project"
},
"NETStandard.Library": "1.6.0",
"NUnit": "3.5.0",
"dotnet-test-nunit": "3.4.0-beta-1"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"netcoreapp1.0",
"portable-net45+win8"
],
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1-*",
"type": "platform"
},
"NSubstitute": "2.0.0-rc"
}
}
},
"testRunner": "nunit",
"version": "1.0.0-*"
}
这是 xUnit - 我将更多地使用它,因为它在 VSTS 上似乎更可行......
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable"
},
"dependencies": {
"System.Runtime.Serialization.Primitives": "4.1.1",
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-build10015",
"NSubstitute": "2.0.0-rc",
"MyLibrary": {
"target": "project"
}
},
"testRunner": "xunit",
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": [
"dotnet5.4",
"portable-net451+win8"
]
}
}
}
更多真正有用的 xUnit 信息在这里 -https://learn.microsoft.com/en-us/dotnet/articles/core/testing/unit-testing-with-dotnet-test
总的来说,我发现,一旦考虑到 VSTS 的工作,xUnit 远远超过了最容易使用的选项 - 您只需设置构建服务器任务以使用 dotnet test 命令行,然后使用发布测试文件任务显示结果。经过一番痛苦之后,我仍然无法让 MS 测试运行在构建服务器上通过。