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

Chapter 9. Organization Of Tests

Good order is the foundation of all good things.

— Edmund Burke

Rules are mostly made to be broken and are too often for the lazy to hide behind.

— Douglas MacArthur

When the number of your tests grows, the way they are written and stored becomes more and more important. This section discusses some decisions relating to various "organizational" aspects of your tests. Even though parts of this section do not contribute directly to your testing abilities, it will surely make you aware of the broader context for your tests. This is because writing a single class is just the beginning: sooner or later your test suite will become huge, and then it will really matter how it is organized.

How your tests are organized is something that will affect not only your work but also that of your teammates. Before you deviate from the most common paths (for example by changing project layout to something non-standard), please make sure that your colleagues also think it is a good idea!

9.1. Package for Test Classes

We have already discussed where source code and test code should be kept. The general consensus is that they should reside in different directories (as shown in Listing 9.1). Such a separation is respected by all currently used tools, and helps us to steer clear of the peril of releasing production code with which some test classes have come to be mingled.

Listing 9.1. Production code and test code in different directories

.

`-- src

|-- main

| `-- java `-- test

`-- java

The subdirectory where production code is kept.

The subdirectory for test code.

However, agreeing on the separate directories does not end the discussion. Another question is about the packages used for test classes.

Basically, there are two possible options:

1.test classes should use the same packages that are used by the production code being tested (e.g. a test for a my.project.User class should also be kept in a my.project package),

2.test classes should use different packages - usually prefixed or suffixed with tests, e.g.

my.project.tests.

The first option still assumes that the test code resides in a different directory from the production code!

190

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