Tuesday, March 07, 2006

Why need to wait for IDEA's JUnit 4 plugin? You can run it now!

Just follow this instruction:

+ In IDEA, go to menu Settings, then click File Templates in Settings dialog
+ In Templates tab, create new item and name it "JUnit 4 Test Class" or anything you want
+ Paste the below code fragment to the text box

package ${PACKAGE_NAME};

import org.junit.*;
import junit.framework.JUnit4TestAdapter;

#parse("File Header.java")
public class ${Name} {
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(${Name}.class);
}

@Before
public void setUp() {

}

@After
public void tearDown() {

}

@Test
public void testSomething() {

}
}

+ Press Apply, then OK
+ When you need to create a JUnit 4 test class, just uses this template
+ When you need to run a JUnit 4 test class, just right click in editor and Run


Note: Ofcourse, you need to add JUnit 4's jar file first (same as JUnit 3).

Enjoy it and happy unit testing! :-)

No comments: