mstestopencoverreportgenerator

Run all the tests but in the report only there are the methods that I want to run


I have to assemblies, one for the tests and the other one is the main assembly that has the methods that I want to test.

In my test assembly I have many classes, each class tests the methods of the class of the main assembly. In total, in all the classes, I have about 300 test methods, but in MyClass01Test I have only 30 test methods. I would like to run only the methods in this class and not all the tests.

I am trying to use this filter:

"-filter:+[*]*.MyMainClass -[*Tests]*"

The problem is that it runs all the tests, no only the tests in MyMainClassTest class in my test assembly. However, in the report that I get with reportgenerator, I get only the methods from MyClass01, that it is correct.

The complete command that I use is this:

"D:\programas\OpenCover\OpenCover.Console.exe" -register:user "-filter:+[*]*.MyMainClass01 -[*Tests]*" -target:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\MSTest.exe" -targetargs:"/testcontainer:\"F:\.MyAssmeblyTests.dll\"" -output:"F:\tests\resutlts.xml"

Solution

  • You have to tell MSTest which tests it should execute. This has nothing to do with OpenCover and ReportGenerator. They only track the execution and create a report.

    You can find the relevant parameters for MSTest here: https://msdn.microsoft.com/en-US/library/ms182489.aspx