3.9. Setup and Tear-down (before and after)

If necessary, you can execute code prior to and after executing each Exemplar. Before doing so, you should consider whether any setup or tear-down code can be obviated by using test isolation techniques such as stubbing and test doubles (see Test Isolation section for details).

You can execute one or more expressions prior to the Exemplar being executed by using the before Exemplar property. The this named instance is available at this stage but retval and $argN are not.

You can execute one or more expressions after the Exemplar is executed by using the after Exemplar property. All named instances available to the expect expressions are available.

@Exemplar(before="TestUtils.setupFoo(this)", after="this{foo=null}")
public void doSomething() {

In the example above, before the Exemplar is executed, the setupFoo static method is called on TestUtils with the object-under-test as the only parameter. After the Exemplar is executed, the foo field of the object-under-test is set to null.

Previous Page   |   Next Page   |   Table of Contents

Comments are closed.