vendredi 29 janvier 2016

Simplify redundant unit tests

I recently joined a team working on a project. I believe something is wrong with the way our unit tests are built.

The objective of the solution is to generate dynamic documents, using sentences that display based on different criteria.

Since most criteria are used in many sentences, we have a "common" class which houses all the functions that return true/false depending on the check. Then in each sentence class, we call one or many criteria functions and display or not, depending on the results.

We have a test class for the common class and one for each sentence class in order to have a good code coverage.

My english is not so great so here is an example :

Common.cs
bool CheckThis()...
bool CheckThat()...

CommonTest.cs
TestMethodForTestThis_caseA()
TestMethodForTestThis_caseB()
[TestMethodsForTestThat]

Sentence1.cs
bool CheckConditions(){
    return CheckThis() && CheckThat();
}

Sentence1Test.cs
TestMethod_CheckThisTrue_CheckThatTrue
TestMethod_CheckThisTrue_CheckThatFalse
TestMethod_CheckThisFalse_CheckThatTrue
TestMethod_CheckThisFalse_CheckThatFalse

I am sure you can imagine what it looks like if you add a few additional Checks. The way I see it, the tests in Sentence1Test are redundant and hurt maintainability. However I don't see how we can do differently but I am certain that I am missing something obvious here.

How should we test our "higher" level methods?

Thanks !

Aucun commentaire:

Enregistrer un commentaire