質問

I have some integration tests written for MsTest. The integration tests have the following structure:

[TestClass]
public class When_Doing_Some_Stuff
{
    [TestInitialize]
    protected override void TestInitialize()
    {
        // create the Integration Test Context
        EstablishContext();

        // trigger the Integration Test 
        When();
    }

    protected void EstablishContext()
    {
        // call services to set up context
    }

    protected override void When()
    {
        // call service method to be tested
    }

    [TestMethod]
    public void Then_Result_Is_Correct()
    {
        // assert against the result
    }
}

I need to filter the code coverage results of a function by who is calling it. Namely, I want the coverage to be considered only if the function is called from a function named "When" or which has a certain attribute applied to it.

Now, even if a certain method in the system is called in the EstablishContext part of some tests, the method is marked as visited.

I believe there is no filter for this and I would like to make the changes myself, as OpenCover is... well.. open. But I really have no idea where to start. Can anyone point me in the right direction?

役に立ちましたか?

解決

You might be better addressing this with the OpenCover developers; hmmm... that would be me then, if you look on the wiki you will see that coverage by test is one of the eventual aims of OpenCover.

If you look at the forking you will see a branch from mancau - he initially indicated that he was going to try to implement this feature but I do not know how far he has progressed or if he has abandoned his attempt (what he has submitted is just a small re-introduction of code to allow the tracing of calls).

OpenCover tracks by emitting a visit identifier and updating the next element in an array that resides in shared memory (shared between the profiler (C++/native/32-64bit) and the console (C#/managed/any-cpu)). What I suggested to him was (and this will be my approach when I get round to it, if no one else does and is why I emit the visit data in this way) that he may want to add markers into the sequence to indicate that he has entered/left a particular test method (filtered on [TestMethod] attribute perhaps) and then when processing the results in the console this can then be added to the model in some way. Threading may also be a concern as this could cause the interleaving of visit points for tests run in parallel.

Perhaps you will think of a different approach and I look forward to hearing your ideas.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top