I have class Foo
:
class Foo
{
public string Bar { get; set; }
}
I have lots of tests which reference this class. How I can ensure that all new properties are tested when my system evolves and I extend Foo
with new property?
I.e. after some time I will add a new property to Foo
class:
class Foo
{
public string Bar { get; set; }
public string Baz { get; set; }
}
I need to review all code which tests my class and ensure that all properties are tested - which is manual process, hard to always get right.
I have class Foo
:
class Foo
{
public string Bar { get; set; }
}
I have lots of tests which reference this class. How I can ensure that all new properties are tested when my system evolves and I extend Foo
with new property?
I.e. after some time I will add a new property to Foo
class:
class Foo
{
public string Bar { get; set; }
public string Baz { get; set; }
}
I need to review all code which tests my class and ensure that all properties are tested - which is manual process, hard to always get right.
There is not much you can do actually to guarantee this. You can try writing a Roslyn analyzer to check for assertions but arguably it would be not worth the effort and probably would not be that feasible.
As alternative you can rely on code coverage tools (integrated into the build pipeline) and setting high coverage target (90+ %).
Another option would be just moving assertions to a method (or set of methods) like:
public void AssertFoo(string expectedBar, string expectedBaz)
{
//
}
Or
public void AssertFoo(Func<string, bool> assertBar, Func<string, bool> assertBaz)
{
//
}
And substitute your assertions to call for such function. And when a new property will be added it would be easy to just modify those functions and code will automatically become incompatible.