ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Taking JUnit Out of the Box
Pages: 1, 2, 3, 4, 5

Here is what a simple TestSuite subclass might look like:

public class MyTestSuite extends TestSuite {
    public static Test suite() {

        TestSuite suite = 
            new TestSuite("Test suite for ...");
        // add the first test
        MyTestCase mtc = 
            new MyTestCase("testSomeTest1");
        // add the second test
        MyTestCase mtc2 = 
            new MyTestCase("testSomeTest2");
        return suite;

Running a test or a test suite is easy, as there are several GUIs you can use, starting with the GUI provided by JUnit and going all the way to IDEs such as Eclipse.

Figure 1 shows how the Eclipse IDE presents a TestSuite.

JUnit integration with Eclipse
Figure 1. JUnit integration with Eclipse

Because it is not the main subject of this article and because there are many articles about JUnit, this article will only provide a brief overview of the basic concepts of JUnit. See the Resources section for articles that cover JUnit in greater depth.

JUnit Strengths and Weaknesses

JUnit is an easy-to-use and flexible open source testing framework. As with every other project, it has many strengths but also some weaknesses. By using the automated JUnit testing framework, which does not need human intervention, one can easily accumulate a large number of JUnit tests and ensure that old bugs are not reproduced. In addition, JUnit helpfully integrates with build utilities, such as Ant, and with IDE utilities, such as Eclipse.

JUnit's weaknesses are also well known. It supports only synchronous testing and offers no support for call backs and other asynchronous utilities. JUnit is a black-box testing framework, so testing problems that do not directly affect functionality (such as memory leaks) is very hard. Additionally, it does not provide an easy-to-use scripting language, so you must know Java to use JUnit.

Another big limitation is that JUnit tests are limited to only one JVM. This limitation becomes a big issue when one is trying to test complex and distributed scenarios. The rest of this article covers this problem and ways to solve it.

Pages: 1, 2, 3, 4, 5

Next Pagearrow