Java Reference
In-Depth Information
Running unit tests through Ant
If your project calls JU nit through Ant, you should be able to run the same unit
tests with IDEA . However, it's also possible to run your test cases through Ant
directly, because it includes its own JU nit test runner (part of Ant's optional pack-
age, but included with IDEA ).
When you execute test cases through Ant, the results are displayed in the Ant
output window along with other build output. Any source code references present
in the test output are hot-linked to the editor, but you won't get the GUI or other
features of the IDEA test runner when running this way. Refer to the Ant docu-
mentation for details on creating JU nit targets in Ant.
7.5 I mproving the quality of the ACME project
In the last chapter, you used IDEA 's debugging features to identify a flaw in the
ACME project. By implementing unit tests (and running them regularly), you can
ensure that bugs like those don't creep in. Listing 7.3 shows a sample JU nit test,
just for illustration, that can be added to your module and used to make sure the
fixed-rate currency exchange service always returns the expected rate. Try adding
it and running it with IDEA using the steps explained in this chapter.
Listing 7.3
JUnit test case that ensures FixedRateCurrencyExchangeService
returns the correct rate
package com.acme.conversion.currency.service;
import junit.framework.TestCase;
public class FixedRateTest extends TestCase {
/**
* To test the fixed rate, we need to do the following:
* 1) Get an instance of the FixedRateCurrencyExchangeService
* 2) From it, request its rate
* 3) Compare that rate with the expected value, which is 1.5
*/
public void testFixedRate() {
FixedRateCurrencyExchangeService service =
new FixedRateCurrencyExchangeService();
assertEquals("Fixed rate was not returned at " +
"expected value",
1.5d, service.getRate(), 0.01d);
}
}
 
 
 
 
 
 
Search WWH ::




Custom Search