This is very simple plugin that generates JUnit test case skeleton including all the methods of tested class.
Here is an example:
Tested Class:
package org.intellij.plugins.junitgen;
public class MyClass
{
public Object getSomePublicValue(){
...
}
protected Object getSomeProtectedValue(){
...
}
Object getSomeDefaultValue(){
...
}
}
Test Case:
package org.intellij.plugins.junitgen;
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.framework.TestCase;
/**
* MyClass Tester.
*
* @author <Authors name>
* @since <pre>09/04/2003</pre>
* @version 1.0
*/
public class MyClassTest extends TestCase
{
public MyClassTest(String name)
{
super(name);
}
public void setUp() throws Exception
{
super.setUp();
}
public void tearDown() throws Exception
{
super.tearDown();
}
public void testGetSomePublicValue() throws Exception
{
//TODO: Test goes here...
}
public void testGetSomeProtectedValue() throws Exception
{
//TODO: Test goes here...
}
public void testGetSomeDefaultValue() throws Exception
{
//TODO: Test goes here...
}
public static Test suite()
{
return new TestSuite(MyClassTest.class);
}
}
If the plugin finds that the test case already exists it prompts you to choose Overwrite or Diff using JDiffFile? plugin.
You can customize the output by modifying junitgen.vm velocity template. All available variables are listed in the template.
Also you can configure the output pattern by modifying junitgen.properties which has following the properties defined:
1. $SOURCEPATH$ - the source path of the tested file. i.e c:/src/junitgen
2. $PACKAGE$ - package of the tested file. i.e org/intellij/plugins/junitgen
3. $FILENAME$ - the name of the output file.
Default output pattern is $SOURCEPATH$/test/$PACKAGE$/$FILENAME$.
i.e c:/src/test/junitgen/org/intellij/plugins/junitgen
To invoke a plugin hit Alt+Insert you will see "JUnit Test" menu in the list.
- Download the binary ZIP file (see below)
- Unzip junitgen.zip in your <%IntelliJRoot%>/plugins directory.
As a result you should have junitgen.jar in plugins dir. and two files in resources directory.
1. junitgen.vm - velocity template
2. junitgen.properties - output configuration file.