Mardoxx
Mardoxx

Reputation: 4482

Code coverage .net core web application targeting net452

How can I get code coverage for a .net core web application which targets net452 in VS2017 (or VS2015)?

I have my tests set up with xUnit but I get no coverage results for the .net core web application. The tests run fine, but I get no coverage!

Is this a known issue?

It doesn't work with MS's test library either.

Quick to repro:

  1. Load up VS2017
  2. Create new ASP.NET Core Web Application (.NET Framework) called WebApplication1
  3. Create TestClass.cs as below
  4. Create new Unit Test Project (.NET Framework) called UnitTestProject1
  5. Add reference to WebApplication1 in UnitTestProject1
  6. Edit UnitTest1.cs as below
  7. Run Test -> Analyze Code Coverage -> All Tests
  8. Open Test -> Windows -> Code Coverage Results
  9. Code coverage only shows unittestproject1.dll

TestClass.cs

namespace WebApplication1
{
    public class TestClass
    {
        public bool TestMethod(bool test)
        {
            if (test) { return true; }
            return false;
        }
    }
}

UnitTest1.cs

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTestProject3
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            var testClass = new WebApplication1.TestClass();
            var val = testClass.TestMethod(true);
            Assert.IsTrue(val);
        }
    }
}

Upvotes: 1

Views: 214

Answers (1)

Mardoxx
Mardoxx

Reputation: 4482

Code coverage is not implemented for netcore projects yet. This support requires datacollectors infrastructure (https://github.com/Microsoft/vstest/issues/309) . It will come post RTW. We recommend that you follow the above issue for updates and fix notifications.

https://developercommunity.visualstudio.com/content/problem/5813/cannot-get-test-coverage-for-net-core-projects.html

Upvotes: 0

Related Questions