Wiki Spaces
Documentation
Projects
Resources
Get Help from Others
Q&A: Ask OpenMRS
Discussion: OpenMRS Talk
Real-Time: IRC Chat | Slack
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"));
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
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.
9 Comments
Roger Friedman
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.
Ben Wolfe
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...
Roger Friedman
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)
Janet Riley
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 .
Jaime Hablutzel
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
Roger Friedman
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.
Abdul Rasheed Tutakhail
When trying to generate test cases in openmrs-api I get "the view that generated the event is unknown". I am using Eclipse Mars on Ubuntu 14.04
Anybody knows what is causing this?
Abdul Rasheed Tutakhail
After having downgraded from Eclipse Mars to Luna, I don't have the error anymore.
Jaime Hablutzel
It is possibly related to the Eclipse API being changed, if you have some time, you can maybe download the plugin source code and debug it, it will be probably required to change only a class or interface name, and you could contribute the fix to anyone.