Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

It is recommended to visibly mark the tests parts with comments // GIVEN// WHEN and // THEN. Especially the WHEN mark is important. Code is the best documentation. Marking the core part of the test allows the developer to figure out what the test does at a first sight. Test maintenance is a major task. Therefore please save the time of your colleagues (and yourself). There are also appropriate methods to dump label for a started test and when/then section. These methods dump markers to logfiles and test output. Therefore it is easier to locate corresponding parts of test output after it is executed.

The test code should look like this:

Code Block
    @Test
    public void test106GetModifiedAccount() throws Exception {
        final String TEST_NAME = "test106GetModifiedAccount";
        TestUtil.displayTestTile(TEST_NAME);

        // GIVEN

		Prepare test environment here        

        // WHEN
		TestUtil.displayWhen(TEST_NAME);

        Do the thing that the test does. Ideally on a single line.

        // THEN
		TestUtil.displayThen(TEST_NAME);

        Check test results, make assertions, check environment
    }

 

Display methods

The test should be completely self-sufficient when it comes to checking the tests results. E.g. use assert methods to check that the test did what it should do. But, the tests need to be maintained and it is often good to display entire objects to help diagnose the test problems. There is a variety of display() methods especially for this purpose. All the display methods write the data both to test log and to standard output.

...