Eclipse templates for JUnit setUp() and tearDown() methods

In a previous post, I suggested Java code templates for standard UIMA/uimaFit structures.
In this post, I add two more templates, this time for JUnit’s “setUp” and “tearDown” methods.

To add these templates to your Eclipse workspace, open the Eclipse preferences via Windows -> Preferences. And navigate to Java -> Editor -> Templates.
Either you use the provided XML files and select Import… or you create a new template with New… and copy the text from below.

@Before

Name: Before
Context: Java
Description: JUnit setUp method

${imp:import(org.junit.Before)}
@Before
public void setUp() throws Exception {
    ${cursor}
}

Download as XML

@After

Name: After
Context: Java
Description: JUnit tearDown method

${imp:import(org.junit.After)}
@After
public void tearDown() throws Exception {
    ${cursor}   
}

Download as XML

Leave a Reply