The Generate Test Case Plugin aides java developers with writing @should style test units.

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(instance.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"));

Eclipse Version

What it Does

How to Install the Plugin Into Eclipse

How to Generate Test Cases

  1. Set up the source and test directories:
  2. Open a java file and add an "@should not return a null object" annotation to a method
  3. Right click in the java file and choose "generate test cases"
  4. Fill in the new unit test method

How to Generate a Test Coverage Report

  1. Open the package explorer
  2. Right click on src/api and choose "Generate Test Coverage Report"
  3. In the menu, go to Window -> Show View -> Other
  4. Open the view for "Other --> Test Report"

Things to do

This is a a list of desired features and bugs to be worked on.

You can download the last svn version of the plugin for eclipse to test some features currently not published through the eclipse update site: org.openmrs.generatetestcases

IntelliJ IDEA Version

You can download the plugin "GenerateTestCases" directly from the IDE. Go to Settings > Plugin enter "GenerateTestCases" hit enter and if not found there should appear a button saying "Search in Repositories" which you should click. Then select the plugin and press install.

An introduction to the plugin is here: https://plugins.jetbrains.com/idea/plugin/5847-generatetestcases

There you can see a Youtube link with a ten minute tutorial to use the plugin.