Module Testings against multiple versions of OpenMRS

It is important to run your unit tests against multiple versions of OpenMRS.  Fortunately, Maven helps facilitate this through the use of configurable properties and build profiles.  The Html Form Entry module has been modified to allow unit testing against different version of OpenMRS.  Some examples from that module are listed below, but also take a look the the module poms themselves for the full gory details.

In the standard module pom configuration, the version of OpenMRS to use is specified as a maven property which can be overriden at the command line.  The following pom snippet defines the OpenMRS version to use as 1.6.3.  This version is referenced elsewhere throughout the module poms.

<properties> <openMRSVersion>1.6.3</openMRSVersion> </properties>

To change the OpenMRS version, you can simple override this property on the command line using the -D parameter:

mvn -DopenMRSVersion=1.7.1 test

This works for the simplest cases, but things quickly become more complex.  Compiling and testing against OpenMRS 1.8 and higher requires a different dependency structure than earlier versions of OpenMRS.  You can configure your module poms using maven profiles.  As an example. here is a pom that has been configured to have build profiles for both 1.6 and 1.8:

First, configure all the common dependencies between 1.6 and 1.8 as normal:

<dependencyManagement> <dependencies> <dependency>     <groupId>org.openmrs.api</groupId>     <artifactId>openmrs-api</artifactId>     <version>${openMRSVersion}</version>     <type>jar</type>     <scope>provided</scope> </dependency> <dependency> <groupId>org.openmrs.web</groupId> <artifactId>openmrs-web</artifactId> <version>${openMRSVersion}</version> <type>jar</type> <scope>provided</scope> </dependency> </dependencies> </dependencyManagement>

Then create two separate profiles to define the version-specific dependencies. Note that the OpenMRS version property is specified within the profiles as well.

You'll have to modify your api and omod poms in a similar way.  Check out the Html Form Entry poms in the github respository to see how it's done.

Now to test/compile against 1.6 or 1.8 you specify a profile on the command line using the -P parameter:

Beyond this step, you may find other customizations required to get test scripts to run against different versions of OpenMRS.  Different versions of OpenMRS require/use different versions of the logic module, so unit tests that test logic must have the proper logic dependency.  One way to do this is to specify the logic version as a maven property, and then define that version in a specific build profile:

If you have defined test datasets within your module, another problem you may run into is that a dataset is only compatible with a specific version of OpenMRS due to data model changes.  One way to get around this is to create a .properties file that sets the dataset xml file to use via a maven property, and then use this .properties file within the test scripts.

Again, the full example can be found by looking at the Html Form Entry module code in the github repository.