All OpenMRS ID accounts have been reset.

Read more and change your password before signing in.
Icon

EXTENDED: OMRS14 Proposals due 30 April! Read more and submit a proposal at OpenMRS Talk.

Skip to end of metadata
Go to start of metadata

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:

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

And then test your implementation code like this

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.

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

Eclipse Version

What it Does

  • Adds a menu item to the "right click" context menu on all .java files called Generate Test Cases
    • A popup menu appears that allows you to choose which of the @should methods you want to generate
    • If a similar ___Test class name exists, a new @Test method is added to the end of it
    • If a similar ___Test class name does not exist, a new test class is added in the /test folder

How to Install the Plugin Into Eclipse

  • Go to Help → Software Updates → Find / Install
  • Choose "Search for new features to install"
  • Click "Add new Remote Site"
  • Enter a name
  • Enter http://resources.openmrs.org/eclipse/update/ as the URL
  • Now choose that remote site and click "Finish"

How to Generate Test Cases

  1. Set up the source and test directories:
    • Right click on your project root and choose properties
    • Next to "Generate Test Cases", set up the pairs: "src/api -> test/api" and "src/web -> test/web"
  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 directly from Settings > Plugin

An introduction to the plugin is here: http://plugins.intellij.net/plugin/?idea&id=5847

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

6 Comments

  1. This does not work with the Maven archetype.
    In order for the test methods to run, they and the resources have to be in the omod project.
    In order to generate tests methods for the api, they and the resources have to be in the api.

    1. How does this not work? If you set the right directories for source and test files it should still generate them correctly. This plugin doesn't do any actually running of the tests...

      1. Because whether you are testing api methods or omod methods, the tests need to be in the omod, but the interface doesn't let you point outside of the current project (fine for omod, too bad for api)

    2. I posted some notes from troubleshooting to the dev list.  Perhaps they'll be helpful.  Please see  https://groups.google.com/a/openmrs.org/d/topic/dev/56uBWZvRb9E/discussion .

  2. Which version is not working, Eclipse or IntelliJ version? I have updated IntelliJ version recently but haven't tested it with any maven archetype, if you clarify it for me I could fix it during these days

    1. I am using Eclipse.
      From recent discussion on the list, it appears that the problem is with the mavenizer or the archetype, it puts tests in the omod when they should be in the api.