dimanche 15 juillet 2018

How to testing something like a converter

i have a question regarding testing classes like a converter. Lets say i have a converter from EntityA to EntityB. The converter seems like this:

public EntityB convert(EntityA){
     //call interal methods
     return B.
}

private xy internalMethod1(...){
   //call other interal Method
}

private xy internalMethod2(...){
   ....
}

private xy internalMethod3(...){
   ....
}

private xy internalMethod4(...){
   ....
}

The converter has one public method and 4 internal methods to convert the entity.

How should i test it?

Option1 I only test the public method and cover all cases from the internalMethods by different example inputs.

Advantages: Testing only the "interface". Dont know the interal structure. Internal refactoring is very easy and needs no changes at the tests.

Disadvantages: Really big maybe unclear tests that tests all cases. Every input must be pass all the methods.

Option2 I write tests for my public method and my private methods. (Some testframeworks can access private methods like powermock or spock (groovy)) I test every method alone and mock every other internal method.

Advantages: Really small tests that only test the method itself and mock all other methods .

Disadvantages: I know how it is implemented internal and must change the tests if i refactor some method, some methodname or something at the internal calling structure

Option3 I write some new classes that do the internal stuff and have public methods

Advantages: Tests are maybe clearer and only for the special classes.

Disadvantages: More classes for one conversion task.

Please help me what is the best practise here. Maybe some good links/hints. Thank you for your time.

Aucun commentaire:

Enregistrer un commentaire