mardi 26 mai 2015

Best practise: one junit test should test exactly one method?

For example Lars Vogel specifies in his article: "A unit test targets a small unit of code, e.g., a method or a class, (local tests). External dependencies should be removed for unit tests, e.g., by replacing the dependency with a test implementation or a (mock) object created by a test framework. "

If I have a class MyClass that has methods a, b, c and d. Method a call method b and c. Method c call method d.

If I have a unit test for method a, testMethodA(), should I (or is it good practise) actually mock all the other method calls in this method a in order just to test method a?

If I would mock return value for other methods called by method a, then I would truly test only method a?

Is there any documentation or reference that show the best practise, what kind of units to test and what to mock?

Aucun commentaire:

Enregistrer un commentaire