我想为我的ASP.NET Core 1.0项目配置NUnit。我试过以下内容:http://www.alteridem.net/2015/11/04/testing-net-core-using-nunit-3/ ,但它在那里用于控制台应用程序。使用ASP.NET MVC Core 1.0配置Nunit
如果我尝试附加一个新项目(类库)到我的解决方案,然后尝试引用我的原始项目 - 它给我参考错误。
这里是我工作:
- 我连着另一个Web应用程序项目,致力于编写测试,我原来的项目,而不是控制台库项目。
- 然后我下载了NuGet软件包:“dotnet-test-nunit”,“NUnit”,“NUnit.Console”和“NUnit.Runners”。
- 然后我写了一个测试,加入这一行后努力project.json:
"testRunner": "nunit"
这是我的测试项目中的project.json文件:
`
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"JustForTest": "1.0.0-*",
"NUnit": "3.4.1",
"NUnit.Runners": "3.4.1",
"NUnit.Console": "3.4.1",
"dotnet-test-nunit": "3.4.0-beta-2"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"testRunner": "nunit",
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}`
我有以下问题:
- 它看起来不像一个优化过程 - 我该如何优化这个?
- 为什么测试不能与控制台应用程序一起工作,可以做些什么来完成这项工作?
任何帮助将不胜感激。我是TDD的新手,在C#编程 - 如果你在这方面有什么建议,请分享一下。
感谢。
感谢您的回答。您的博客在逐步显示流程的过程中非常有帮助。 – Blaze
我也必须感谢你Rob,我的测试在Visual Studio中运行良好。虽然我似乎无法让他们在VSTS/Visual Studio Online上运行。我发现的所有文章都建议使用测试适配器nuget软件包 - 在.net内核中都不支持这些软件包。 –
我试图完全实现NUnit,MSTest和xUnit的本地和VSTS使用,并发现xUnit支持的最好 - 详细信息和链接http://stackoverflow.com/q/40093573/2579219 –