Basically what I’ve been doing is introducing the “@should” javadoc annotation. Each api method will get one or more @should annotations that simply state a behavior of that method need testing, in other words, each @should annotations should be phrased. For instance:
- @should not fail given null parameter
- @should return empty list if no results
The example above would become unit test named (given the method was findPatient):
- public void findPatient_shouldNotFailGivenNullParameter()
- public void findPatient_shouldReturnEmptyListIfNoResults()
These are the step I followed to get started on this task:
- Import the OpenMRS-core Repository from Eclipse
- In Eclipse, choose File:Import
- Choose Git: Projects from Git
- Select Repository Source: URI
- Browse the location of the local file on the PC (file: openmrs-core)
- Select the master branch
- Choose the directory you want to clone into
- Select Use the New Project Wizard
- Choose Java: Java Project
- Enter a project name (To get all files imported, the given name has to be exactly the same as the local file name. In this case the project name should be: openmrs-core)
- Start searching all methods that do not have tests
- In Git Bash, type command: $grep –r ‘@should’ openmrs-core (This command line will recurs into sub-directories to look for all “@should” instances)
- Command: $grep –r ‘@should’ openmrs-core > file.txt (This line will save the output to a file text)
- Browse ‘@should’ annotations in the packages
- The txt.file will output all packages that still have ‘@should’ annotations.
- In Eclipse, look for such packages and start modifying them, so those methods become unit test names.
- For example: /api/src/main/java/org/openmrs/somepackage/SomeObject.java:
In Eclipse: /api/src/main/java/org/openmrs/aop/AuthorizationAdvice.java:
From the blog Naty Zelaya » CS@Worcester by natyzelaya and used with permission of the author. All other rights reserved by the author.