Tags in my blog

13 April 2009

How to use JUnit

To perform unit testing using JUnit, simply just add @org.junit.Test annotation before the test method.

You can run your testing class by invoking main method from JUnitCore like this:

java org.junit.runner.JUnitCore TestClass1 TestClass2 ...

If you expect certain Exception have to thrown by a JUnit test method, you can annotate the method like this:

@Test(expected = IndexOutOfBoundsException.class) public void empty() {
new ArrayList<object>().get(0);
}

No comments: