Java Reference
In-Depth Information
elements. In our case, JU nit calls the three-argument constructor E with the first
element in the array, itself an array: {2, 1, 1} . JU nit then calls each @Test method
F as usual. JU nit repeats the process for the next array in the getTestParameters
collection D .
When you compare the test results with the previous example, you see that instead
of running one test, the parameterized JU nit test runner ran the same method three
times, once for each value in our @Parameters collection.
The JU nit class Parameterized is one of JU nit's many test runners. A test runner
allows you to tell JU nit how a test should be run. Next, we look at the other JU nit
test runners.
2.3
JUnit test runners
When you're first writing tests, you want them to run as quickly and easily as possible.
You should be able to make testing part of the development cycle: code-run-test-code (or
test-code run-test if you're test-first inclined). There are IDE s and compilers for quickly
building and running applications; JU nit lets you build and run tests.
2.3.1
Test runner overview
JU nit 4 is built with backward compatibility with version 3.8.x. Because the 4.x version
of JU nit is completely different from the 3.x versions, it should be possible to execute
not only JU nit 4 tests but also 3.x-style tests. That's why in its latest versions JU nit pro-
vides different runners (listed in table 2.3) for running JU nit 3.x tests, JU nit 4 tests,
and different sets of tests.
Table 2.3
JUnit 4 test runners
Runner
Purpose
org.junit.internal.runners.JUnit38ClassRunner This runner is included in the cur-
rent release of JUnit only for
backward compatibility. It will
start the test case as a JUnit 3.8
test case.
This runner will start the test
case as a JUnit 4 test case.
org.junit.runners.JUnit4
A Parameterized test runner
runs same sets of tests with dif-
ferent parameters.
org.junit.runners.Parameterized
org.junit.runners.Suite
The Suite is a container that
can hold different tests. The
Suite is also a runner that exe-
cutes all the @Test annotated
methods in a test class.
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search