views:

356

answers:

2

What are the patterns and dos and don'ts when one is writing tests for Javolution tests? In particular I was wondering:

  • TestCase.execute() does not allow throwing of exceptions. How to deal with them? Rethrow as RuntimeException or store in a variable and assert in TestCase.validate() or something?
  • Are there any graphical runners that show you the tests that fail, i.e. in Eclipse? Perhaps someone wrote a JUnit-Wrapper such that I could use the Eclipse JUnit Runner?
+1  A: 

The javadoc and javolution sources give some examples and design rationale. See also an article on serverside.

Javolution tests contain exactly one test, and the exercising of the tested code is separated from the validation into different methods execute() and validate(). Thus the same testclass can be used both for regression tests and speed tests (where the call to validate() is omitted). Also the execution of many tests is trivially parallelizable.

A disadvantages of this separation is: you will get more memory consumption, since the results of the execution of the exercised code needs to be saved until calling validate(). (Freeing those results in tearDown is probably a good idea.) And if validate comes from a different class than exercise then it might be difficult to debug a failure.

hstoerr
A: 

You can get some kind of graphical testrunner by using the following JUnit adapter and running it in eclipse. You can start / debug the failed tests separately. Unfortunately the graphical representation does not include anything about the actual test - it just shows the numbers [0], [1], etc.

@RunWith(Parameterized.class) public class JavolutionJUnit4Adapter {

protected final javolution.testing.TestCase test;

public JavolutionJUnit4Adapter(javolution.testing.TestCase testcase) {
    this.test = testcase;
}

@org.junit.Test
public void executeTest() throws Exception {
    enter(REGRESSION);
    try {
        new javolution.testing.TestSuite() {
            @Override
            public void run() {
                test(test);
            }
        }.run();
    } finally {
        exit();
    }
}

@Parameters
public static Collection<javolution.testing.TestCase[]> data() {
    javolution.testing.TestSuite fp = new WhateverSuiteYouWantToRun();
    List<javolution.testing.TestCase> tests = fp.getTestCases();
    Collection<javolution.testing.TestCase[]> res = new ArrayList<javolution.testing.TestCase[]>();
    for (javolution.testing.TestCase t : tests) {
        res.add(new javolution.testing.TestCase[] { t });
    }
    return res;
}

}

hstoerr