Monday, July 25, 2011

Junit 4

Just common JUnit 4 usages for my reference

JUnit 4 uses annotations, so naming convention is no more needed, which means

For Test Suite:

  • Test suite class doesn't have to extend the TestSuite class.
  • adding test cases is different from the way in JUnit 3

@RunWith(Suite.class)
@Suite.SuiteClasses({

testclass1.class;
testclass2.class;
...
})

public class MyTestCases{

}


For Test Cases:
  • the test class doesn't have to extend TestCase
  • the test method name doesn't have to start with test

@Test
annotates test method in test class.

@Before and @After
test method level setUp and tearDown, they run before and after every test case.

@BeforeClass and @AfterClass
class level setUp and tearDown, they run once before and after all test cases.

@Ignore
ignore the test case, for example: @Ignore ("Not ready to run for now.")

Friday, October 3, 2008

junit.framework.JUnit4TestCaseFacade signer issue in Eclipse

When running a junt test in Eclipse (Ganymede), I got the following exception:

java.lang.SecurityException: class "junit.framework.JUnit4TestCaseFacade"'s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(ClassLoader.java:775)

It looks like the problem is because the Eclipse is using Junit 4. As soon as I switched it to Junit 3, it works fine.

To switch from Junit 4 to Junit 3. Click "Run" -> "Run configurations..."->"Test runner".