How to unit test Asp.net core WebAPI (net452) project? -
i have asp.net core web.api project.
(only) targets net452 framework.
question is: how unit test asp,net core webapi (net452) project?
i tried adding classic .net unit testing project solution, reference web.api core project. reason, i'm not able declare (refer) class inside webapi project. this, conclude, cannot use classic unit testing project test asp.net core project.
inside project.json:
"frameworks": { "net452": {} } }
this how solution looks like:
inside test class:
[testclass] public class activedirectoryclientprovidertests { [testmethod] public async task get_should_return_client() { //var settings = new activedirectorysettings(); ng2aa_demo.domain.avatar.getavatarbyuserhandler } }
you can use xunit or nunit, both works .net core.
here tutorial on how create unit test project: https://docs.microsoft.com/en-us/dotnet/articles/core/testing/unit-testing-with-dotnet-test
you create .net core class library, import xunit or nunit library , set unit test runner.
an example of project json using xunit:
{ "version": "1.0.0-*", "testrunner": "xunit", "dependencies": { "microsoft.netcore.app": { "type":"platform", "version": "1.0.0" }, "xunit":"2.1.0", "dotnet-test-xunit": "1.0.0-rc2-192208-24", "primeservice": { "target": "project" } }, "frameworks": { "netcoreapp1.0": { "dependencies": { "microsoft.netcore.app": { "type": "platform", "version": "1.0.0" } }, "imports": [ "dotnet5.4", "portable-net451+win8" ] } } }
taken here
Comments
Post a Comment