Java Reference
In-Depth Information
JU nit will use a default test runner if none is provided based on the test class. If you
want JU nit to use a specific test runner, specify the test runner class using the @Run-
With annotation, as demonstrated in the following code:
@RunWith(value=org.junit.internal.runners.JUnit38ClassRunner. class )
public class TestWithJUnit38 extends junit.framework.TestCase {
[...]
}
Now that we've seen an overview of the different test runners and how to direct JU nit
to use them, we look at various test runners in more detail.
2.3.2
The JUnitCore façade
To make running tests as quick and easy as possible, JU nit provides a façade
( org.junit.runner.JUnitCore ), which operates with any of the test runners. JU nit
designed this façade to execute your tests and gather results and statistics. You can see
the JUnitCore class in action in figure 1.3 in the previous chapter.
Design patterns in action: façade
A façade 1 is a design pattern that provides a unified interface to a set of interfaces
in a subsystem. Façade defines a higher-level interface that makes the subsystem
easier to use. You can use a façade to simplify a number of complicated object
interactions into a single interface.
The JU nit façade determines which runner to use for running your tests. It supports
running JU nit 3.8 tests, JU nit 4 tests, and a mixture of both. 1
Before JU nit 4, JU nit included Swing and AWT test runners; these are no longer
included. Those graphical test runners had a progress indicator running across the
screen, known as the famous JU nit green bar. JU nit testers tend to refer to passing
tests as green bar and failing tests as red bar . “Keep the bar green to keep the code clean”
is the JU nit motto.
Figure 2.1 shows the Eclipse JU nit view after a green-bar test run.
These days, all major IDE s support integration with JU nit.
2.3.3
Custom test runners
Unlike other elements of the JU nit framework, there is no Runner interface. Instead,
the various test runners bundled with JU nit all extend the org.junit.runner.Runner
class. To create your own test runner, you'll need to extend the Runner class. Please
refer to appendix B, where we cover this topic in detail.
1
The definition is taken from the Portland Pattern Repository: http://c2.com/cgi/wiki?FacadePattern.
 
 
 
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search