JUnit Generator template

I am trying to change my template to generate a JUnit4 class. Everything works (including /../test/ to send the classes to the test director), except the individual methods are not being generated. Can someone help?



########################################################################################
##

    1. Available variables:

    2. $entryList.methodList - ArrayList of method names

    3. $entryList.fieldList - ArrayList of class scope field names

    4. $entryList.className - class name

    5. $entryList.packageName - package name

    6. $today - Todays date in MM/dd/yyyy format

##

    1. You can configure the output class name using "testClass" variable below.

    2. Here are some examples:

    3. Test${entry.ClassName} - will produce TestSomeClass

    4. ${entry.className}Test - will produce SomeClassTest

##
########################################################################################
##
#macro (cap $strIn)$strIn.valueOf($strIn.charAt(0)).toUpperCase()$strIn.substring(1)#end

    1. Iteratre through the list and generate testcase for every entry.

#foreach ($entry in $entryList)
#set( $testClass="${entry.className}Test")
##
package $entry.packageName;

import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**

  • ${entry.className} Tester.

*

  • @author Norris Shelton

  • @since <pre>$today</pre>

  • @version $Revision$

*/
public class $testClass {

/**

  • Set-up the test. Open a database connection, create test records or anything else you need to do.

*/
@Before
public void setUp() {
// do something
}

#foreach($method in $entry.methodList)
/**

  • Perform a test.

*/
@Test
public void test#cap($)() {
//TODO: Test goes here...
// assertNotNull(...);
// assertTrue(...);
}

#end
/**

  • Tear-down the test.

*/
@After
public void tearDown() throws Exception {
// do something
}

}
#end

1 comment
Comment actions Permalink

Greetings,
Check to see if the methods in the class under test are annotated. I've discovered that annotations prior to function declarations break unit test generation using JUnitGenerator.

Hope that helps.

-- Morgan

0

Please sign in to leave a comment.