Java Reference
In-Depth Information
might want to assert that a critical method never takes too long to execute. Listing 4.2
shows a timed test.
Listing 4.2
Enforcing a timeout on a method with JUnit
package com.manning.junitbook2;
import org.junit.Test;
public class ExampleTimedTest {
B
@Test(timeout=5000)
public void someVeryLongTest() {
[...]
}
}
The example uses the timeout parameter B on the @Test annotation to set a timeout
in milliseconds on the method. If this method takes more than 5,000 milliseconds to
run, the test will fail.
An issue with this kind of test is that you may need to update the timeout value
when the underlying hardware changes, the OS changes, or the test environment
changes to or from running under virtualization.
A CCEPTANCE SOFTWARE TESTING
It's important that an application perform well, but the application must also meet
the customer's needs . Acceptance tests are our final level of testing. The customer or a
proxy usually conducts acceptance tests to ensure that the application has met what-
ever goals the customer or stakeholder defined.
Acceptance tests are a superset of all other tests. Usually they start as functional
and performance tests, but they may include subjective criteria like “ease of use” and
“look and feel.” Sometimes, the acceptance suite may include a subset of the tests run
by the developers, the difference being that this time the customer or QA team runs
the tests.
For more about using acceptance tests with an agile software methodology, visit the
wiki site regarding Ward Cunningham's fit framework ( http://fit.c2.com/).
4.2.2
The three types of unit tests
Writing unit tests and production code takes place in tandem, ensuring that your
application is under test from the beginning. We encourage this process and urge pro-
grammers to use their knowledge of implementation details to create and maintain
unit tests that can be run automatically in builds. Using your knowledge of implemen-
tation details to write tests is also known as white box testing .
Your application should undergo other forms of testing, starting with unit tests and
finishing with acceptance tests, as described in the previous section.
As a developer, you want to ensure that each of your subsystems works correctly. As
you write code, your first tests will probably be logic unit tests. As you write more tests
and more code, you'll add integration and functional unit tests. At any one time, you
 
 
 
 
 
Search WWH ::




Custom Search