Trying to understand how it works


Hello, I'm running the trial version of ReSharper and I'm trying to learn how dotCover works. Sometimes I understand that a function can return different outputs so I can make an easy test to validate it. But I have an attribute for my classes and I don't understand why it says "Statement uncovered by tests".

public class TableAttribute
    public string Name { get; }
    public Name(string name)
        Name = name;

It's an attribute that I can put in a model class so I can know on runtime the name of it's table in case the name of the class is different of the name of the table.

 Also why some void functions also shows "uncovered"? For example it's a function that simply writes a log. What should I test with that function, if an exception is thrown?


1 comment
Comment actions Permalink


Unfortunately, I was out of the forum for some time. So I apologize if the answer is not actual anymore.

dotCover performs method statement-level run-time application analysis. It starts an application and checks which methods and which statements in these methods were executed during the application run. If some method statement was executed, it's considered as covered. So dotCover can't say whether some source code entity is used somewhere in the application if this entity is not a method (e.g. a class field, or an attribute class).

Regarding attribute classes: if you just mark some class in your code with some attribute, all methods of the attribute class will be shown as uncovered by dotCover, because the instance of the attribute class is never created in this case and so methods are never called. You can check this by putting a breakpoint in the attribute class constructor and trying to debug your application (unit tests).

But if you add a code which examines the attributes of your class, the constructor of the attribute will be shown as covered, because an attribute class instance is created during the examination. If you then try to get some attribute property's value (Name in our case), the property's getter will be sown as covered:

public class Some
public void Foo() {}

public class UnitTest1
  public void TestMethod1()
    var tableAttribute = typeof(Some).GetCustomAttributes(true).OfType<Table>().Single();


Please sign in to leave a comment.