Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Tomek Kaczanowski - Practical Unit Testing with JUnit and Mockito - 2013.pdf
Скачиваний:
224
Добавлен:
07.03.2016
Размер:
6.59 Mб
Скачать

Chapter 11. Test Quality

reveals various weaknesses of the production code. This is yet another benefit of having your test code reviewed!

When reading this section you might have a certain feeling of déjà vu. This is because many of the issues mentioned here simply invert good practices described elsewhere in the various chapters of this book.

11.5.1. A Three-Minute Test Code Review

Code reviews take time. In an ideal world, we would have this time, but in reality things are different. Let us now see what can be done to perform a very quick test code review, so that next time when you have only three minutes and are hesitating about whether to do it at all, you will have a short checklist of things which could be validated, even in such a short time.

Size Heuristics

Some idea of test code quality might be gained by looking at the following features of the test code:

the number of imported classes,

the number of test doubles used,

the length of set-up methods,

the length of test methods,

the length of test class.

It is not possible to come up with exact numbers here - which should trigger a red light in your head. However, common sense is usually enough to distinguish right from wrong. For example, three test doubles in a test class are probably fine, but if there are eight of them, then an alarm bell should ring. And what about four, five, six or seven test doubles? Where is the exact border? As usual, "it depends", and you need some more time to decide whether or not things are fine. The same holds true for the number of imports (and the variety of imported classes).

As for the length of the test methods and classes, here, again, common sense should be sufficient.

Once again, please remember that finding weaknesses in any of the above might be a symptom of bad production code, which is only reflected by the test code. Violations of reasonable size values for test code usually indicate that the class being tested has too much responsibility.

But do They Run?

Unit tests should run in a matter of seconds, so three minutes will give you enough time to run all of them.

Is there a build script which allows anyone to execute them, or do they need some manual setup (e.g. running your IDE)? If the latter, then this is something to really worry about.

How much times does it take for tests to finish? If it is more than 20 seconds (again, this is not a value you should take too literally), then these are probably not unit tests but integration tests.

Are they really run - do they really get picked out by your build script?

250

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]