Tag Archives: intellijidea

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