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

Chapter 8. Getting Feedback

8.9. Exercises

The exercises presented in this section should make you familiar with the default output of tests. They should also give you some practical experience with the customization of elements responsible for the content and format of various test execution reports.

8.9.1. Study Test Output

Simply run some tests and study the output. Make sure you know where to find information on the cause of a failed test. Remember, there are usually several ways to obtain the required information. Spend some time getting to know them all, so you can choose the one which suits you best.

8.9.2. Enhance the Custom Rule

Enhance your custom rule (from Section 6.8.2), so that it will be possible to:

apply it only to tests annotated with @Retry annotation,

specify the number of retries.

Listing 8.8. Sample test using the enhanced RetryTestRule

public class EnhancedRetryTest {

@Rule

public RetryTestEnhancedRule retryTestRule = new RetryTestEnhancedRule();

@Test @RetryTest(retryNb = 1)

public void shouldBeRerunOneTime() { ... }

@Test @RetryTest(retryNb = 2)

public void shouldBeRerunTwoTimes() { ... }

@Test

public void shouldNotBeRerun() { ... }

}

8.9.3. Custom Test Listener

In Section 8.3 we have implemented a simple listener which prints the execution time of test methods. Your job is to enhance it with the following functionality:

output from this custom listener will be printed after all tests are finished,

both method and class name will be printed,

the result of the test will be printed ("ok" or "FAIL"),

printed data will be sorted in descending order,

printed time will be more "humanly readable" (e.g. it has a "ss:mm:ms" format), and everything is nicely aligned.

188

Chapter 8. Getting Feedback

An example of the output expected is presented below:

Listing 8.9. Sample output of the EnhancedTimeTestListener class

ok

MyClassTest.secondTest

00:09:876

FAIL

AnotherClassTest.someTest

00:03:333

ok

AnotherClassTest.someTest

00:02:222

ok

MyClassTest.firstTest

00:00:123

 

 

 

8.9.4. Debugging Session

Make yourself comfortable with the debugging of tests. Using your favorite IDE, set some breakpoints (in test code and in the source code of the tested classes) and execute some tests. Practise working through all the typical scenarios of a debugging session:

setting breakpoints,

getting information on the values of variables,

various types of moving forward (step into, step over, etc.).

189

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