Java Tutorial/Trail: Java software testing

Java software testing edit

Unit testing in Java has become quite convenient with frameworks like JUnit. The test cases are classes in the same packages as the classes they are meant to test, but they do not necessarily reside in the same directories. Test cases and tested classes are often combined from different classpath entries in order to seperate compile time and run time content. The test cases perform tests on methods and aspects of methods; besides the most common execution paths they also verify boundary conditions, special cases and even the correctness of the exceptions thrown by a method. The exceptions thrown by a method are part of its contract and thus must be tested for correctness, which is obvious in cases where exceptions are caught and further program execution depends on the type or details of the exception caught.

A test case should aim to be as simple as possible but as complex as necessary in order to test a given aspect. Complex test code should be refactored into test case and supporting methods. The supporting methods can then be tested independently and the test no longer relies on the correctness of complex code that cannot be tested.

JUnit edit

See also edit

External links edit