Create Eclipse template for unit tests

Hello all!

I just wanted to share what I just found out, maybe its not new to you, but it might take away some pain for others in writing unit tests :wink:

In Eclipse go to the “Quick Access” search for “Templates” and in the java section click “Add new Template” and add this one

Back in the editor, type the name of the template “openmrstest”, CTRL+SPACE for the context menu and then hit enter. Now you can edit the variables like “methodToBeTestedName” and it will edit all occurrences. And your good to go to write your test :smile:

Hope you find it useful!

If somebody knows a few more tricks (for ex. how to use functions in the template to process the string you type in ${shouldTestThis} in lower case with spaces to show up in @verifies value =, but in upper case without spaces in the method signature), please tell us!

2 Likes

I love your spirit of sharing. Please keep it up!!! :slight_smile:

By the way, did you by any chance have a look at? https://wiki.openmrs.org/display/docs/Generate+Test+Case+Plugin

no I havent :smile:thanks a lot, thats a great plugin!!! is having the @verifies in the javadoc of the unit test the older way of writing the test? and is it now preferred to use the @verifies method annotation?

No, it’s the other way round: @verifies in the javadoc is the “new” way.

(That said, in retrospect the whole idea is a bit misguided, and we ought to be using a proper test coverage tool in CI instead of this.)

oh good to know, we did it the other way in the radiology module :frowning:

is there a plan to integrate a library like http://eclemma.org/jacoco/trunk/doc/maven.html into the core and then use for ex. coveralls like the hl7 hapi project does for test coverage? I was thinking about it for the radiology module.

Isn’t JaCoCo the default code coverage engine used in Sonar, which we are already using? https://wiki.openmrs.org/display/docs/Sonar

that is nice! it states that modules are not yet able to get those metrics, is that still true? would be nice for modules to get on the sonarqube train :smile:

Do you have some spare cycles to add a couple of them to the train? :slight_smile:

is this only a matter of configuration? can you maybe point me to a wiki? I would definitely look into it

I think we’re concerned about server load (and visual noise in CI), so I’m not sure we want to open the door to modules that aren’t in an official OpenMRS distro yet.

I would have liked to see all modules and OpenMRS related stuff in one place. If the server load and visual noise is a concern, I’ve previously used https://coveralls.io . I recommend using that for anyone wants to do code coverage for opensource repos. Instead of using travis and coveralls separately, you can also combine them through travis.yml like this - https://godjango.com/25-travis-ci-and-coveralls/