Java Reference
In-Depth Information
discussed in chapter 5. If enabled, the first option displays the setup dialog each
time you run the test, giving you the option of tweaking the settings before exe-
cution. The second option causes IDEA to force a rebuild before running the test.
Enabling this option lets you edit your tests and then run them without having to
explicitly request a new build. On the other hand, you can disable this option if
you're rerunning tests without code changes. Remember that these options are
global, and they affect all your Run/Debug configurations, not just your unit tests!
7.3.2
Running your unit test configuration
The basic use of Run/Debug configurations was covered in chapter 5. Unlike appli-
cation targets, which execute via their main() method, JU nit configurations pass
the selected test class or classes to a test runner for processing—no main() method
is required. The test runner locates and executes the tests and reports the results.
Running a selected Run/Debug configuration
Once your test target is configured, select it from the Run/Debug drop-down on
the toolbar in the Run/Debug Configurations dialog, or from the Run menu,
and then click the Run icon on the toolbar or press Shift-F10 . IDEA understands
that running a JU nit test means launching the test runner, rather than executing
the class directly. JU nit tests can be distinguished from other entries in the Run
list by their icon.
All tests run in the background, and you can execute multiple tests simul-
taneously if you wish. Each test gets its own tab in the Run tool window.
TIP
Defining temporary test targets
IDEA provides a convenient shortcut for creating and running test targets. When
you select a package, class, or method in the project or structure windows, the
right-click pop-up menu provides an option for running test cases for that selec-
tion, if there are any. If you've created a testing Run/Debug configuration, it's
used. If not, a temporary target is created and added to the list of test configura-
tions, and the test executes. Temporary targets are particularly handy when
you're trying to debug a single test method. You can create a temporary target to
run the method, using it until you correct the problem.
This shortcut works from the editor as well. Right-click inside the body of a
test method from the editor, and select the Run option to run the test (or press
Ctrl+Shift+F10 ). Clicking anywhere else inside the file allows you to execute the
entire test case. See figure 7.2.
 
 
 
 
 
 
Search WWH ::




Custom Search