【发布时间】:2023-03-09 00:15:01
【问题描述】:
我想为我的 ASP.NET Core 1.0 项目配置 NUnit。我试过以下:http://www.alteridem.net/2015/11/04/testing-net-core-using-nunit-3/ ,但它适用于控制台应用程序。
如果我尝试将新项目(类库)附加到我的解决方案,然后尝试引用我的原始项目 - 它会给我带来引用错误。
这对我有用:
- 我将另一个专门用于编写测试的 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# 中编程 - 如果您在这方面有任何建议,也请分享。
谢谢。
【问题讨论】:
标签: c# tdd nunit asp.net-core-mvc asp.net-core-1.0