Is there a testing technique to verify all properties have been tested

184 views Asked by At

I have the following situation and any help would be appreciated.

public class Poco
{
  public string SomeData { get;set; }
  public string SomeMoreData { get;set; }
}

public class Worker
{
     public Poco DoWork()
     {
         // do stuff
     }
}

TESTING METHOD A.......

[Test]
public static void TestPocoIsPopulated()
{
    var objUt = new Worker();
    var actual = objUt.DoWork();       
    var expected = new Poco { SomeData = "reusltOne", SomeMoreData = "resultTwo" };

    actual.ShouldBeEquivalentTo(expected);

}

This works fine. However, with larger tests of nested classes, using ShouldBeEquivalentTo() becomes cumbersome, and I'd like to be able to do this as follows...

EDIT: Also with Method A you cant do this.... var expected = new Poco { SomeData = [NOT_NULL] , SomeMoreData = "resultTwo" };

TESTING METHOD B.......

[Test]
public static void TestPocoIsPopulated()
{
    var objUt = new Worker();
    var actual = objUt.DoWork();    

    actual.SomeData.Should().Be("resultOne");
    actual.SomeMoreData.Should().Be("resultTwo");
}

However, if I add a new property to Poco, then Testing Method B does not complain, and the property may not get tested. Using Method A however, the test will fail as ShouldBeEquivalentTo() will note that the new property is null

So, my question is, is there a method C as follows.

TESTING METHOD C.........

[Test]
public static void TestPocoIsPopulated()
{
    var objUt = new Worker();
    var actual = objUt.DoWork();    

    actual.SomeData.Should().Be("resultOne");
    actual.SomeMoreData.Should().Be("resultTwo");

    actual.Should().HaveAllPropertiesBeenTested().EqualTo(true); // <-------- is this possible?

}
1

There are 1 answers

0
Dennis Doomen On BEST ANSWER

The ultimate question to your answer is no, we don't support verifying whether all properties have been tested. That would require some kind of proxy generation technique that tracks access to a property. I must admit it is an interesting idea, so you could propose an enhancement on https://github.com/dennisdoomen/FluentAssertions/issues?state=open