Generate Test Cases Intellij Plugin

Generates Test Cases is a port of Eclipse’s generate test cases plugin described here:
http://wiki.openmrs.org/display/archive/Generate+Test+Case+Eclipse+Plugin

This project aims to make it easier to make TDD with a really cool and easy approach that consist in
annotating interface method with desired behaviours like this:

public interface Person {

/**
*
* @return
* @should say hello, and nothing more that that
*/
String sayHello();
}

So with this plugin you could generate a test class for this interface like this one automatically:

import org.junit.Assert;
import org.junit.Test;

public class PersonTest {

/**
* @see Person#sayHello()
* @verifies say hello, and nothing more that that
*/
@Test
public void sayHello_shouldSayHelloAndNothingMoreThatThat() throws Exception {
//TODO auto-generated
Assert.fail(“Not yet implemented”);
}
}

And then test your implementation code like this

public void sayHello_shouldSayHelloAndNothingMoreThatThat() throws Exception {
assertThat(intance.sayHello(), is(“hello world”));

}

This way you can realize that for testing this behaviour you just wrote the should annotation in the sut (system under test) in a really
descriptive way.

/**
*
* @return
* @should say hello, and nothing more that that
*/
String sayHello();

Auto-generated the test class and test method (using the plugin) and then tested the actual expected behaviour with (hamcrest style junit test):

assertThat(intance.sayHello(), is(“hello world”));

If you want to try it out you will need to install it in you IntelliJ IDEA as a plugin, you can use the regular plugin installation manager from inside intellij, just type ‘GenerateTestCases’ to find the plugin and install it, remember you will need to restart IntelliJ IDEA to get it working.

Here you can see a video showing you how to install and make basic usage of the plugin:

Here http://www.youtube.com/watch?v=WYET6PECxuc you can see a 10 minutes video explaining the usage of the plugin

6 thoughts on “Generate Test Cases Intellij Plugin”

  1. Thanks for good plugin. Another good thing you probably can do – please, make it supporting TestNG. Other wise, it sometimes throws exceptions like
    Error during dispatching of java.awt.event.KeyEvent[KEY_PRESSED,keyCode=117,keyText=F6,keyChar=Undefined keyChar,modifiers=Shift,extModifiers=Shift,keyLocation=KEY_LOCATION_STANDARD,rawCode=117,primaryLevelUnicode=0,scancode=64] on frame0
    java.lang.NullPointerException
    at com.intellij.generatetestcases.util.BddUtil.getPsiDocTagParent(BddUtil.java:78)
    at com.intellij.generatetestcases.refactor.ShouldDescriptionNameSuggestionProvider.getSuggestedNames(ShouldDescriptionNameSuggestionProvider.java:32)
    at com.intellij.refactoring.rename.RenameDialog.getSuggestedNames(RenameDialog.java:141)
    at com.intellij.refactoring.rename.RenameDialog.c(RenameDialog.java:118)
    at com.intellij.refactoring.rename.RenameDialog.(RenameDialog.java:78)
    at com.intellij.generatetestcases.refactor.ShouldTagsAwareRenameProccessor.createRenameDialog(ShouldTagsAwareRenameProccessor.java:43)
    at com.intellij.refactoring.rename.PsiElementRenameHandler.a(PsiElementRenameHandler.java:151)
    at com.intellij.refactoring.rename.PsiElementRenameHandler.rename(PsiElementRenameHandler.java:143)
    at com.intellij.refactoring.rename.PsiElementRenameHandler.invoke(PsiElementRenameHandler.java:95)
    at com.intellij.refactoring.rename.PsiElementRenameHandler.invoke(PsiElementRenameHandler.java:61)
    at com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler.performDialogRename(VariableInplaceRenameHandler.java:130)
    at com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler.doRename(MemberInplaceRenameHandler.java:84)
    at com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler.invoke(VariableInplaceRenameHandler.java:87)
    at com.intellij.refactoring.actions.BaseRefactoringAction.actionPerformed(BaseRefactoringAction.java:89)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$3.performAction(IdeKeyEventDispatcher.java:542)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:590)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.d(IdeKeyEventDispatcher.java:458)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:206)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:524)
    at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:420)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:378)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

    Inellij IDEA v.11.1.3, jdk 1.6.0_31

  2. Hi, thanks for a awesome awesome plugin! May I ask, is it planned to add Scala code generation support? That way the tests could be written in Scala. Thank you, Sebastian

  3. Thank you for the useful plugin, which will help establish good practice in writing unit testing code.

    I ran into an issue when running intellij idea 64 bit exe. While the 32 bit version runs fine, 64 bit version caused some error when intellij idea started and is not available. The intellij version I am using is 12.

    Can you look into this?

    Thanks
    Haixi

Leave a Reply

Your email address will not be published. Required fields are marked *