I wanted to configure NUnit for my ASP.NET Core 1.0 project. I have tried following : http://www.alteridem.net/2015/11/04/testing-net-core-using-nunit-3/ , but it's there for console applications.
If I try to attach a new project (class library) to my solution and then try to reference my original project - it gives me reference error.
Here is what worked for me:
- I attached another web app project, dedicated to writing tests, to my original project, as opposed to the console library project.
- Then I downloaded NuGet packages for : "dotnet-test-nunit", "NUnit", "NUnit.Console" and "NUnit.Runners".
- Then I wrote a test which worked after adding this line to project.json:
"testRunner": "nunit"
This is the project.json file from my test project:
`
{
"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%" ]
}
}`
I have following questions:
- It don't seems like an optimized process - how can I optimize this?
- Why test didn't worked with console application, could something be done to make that work?
Any help will be much appreciated. I am new to TDD and for that matter programming in C# - if you have any suggestion in this context, kindly share that as well.
Thanks.