Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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 we 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.

...

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  As an example. here is a pom that has been configured to have build profiles for both 1.6 and 1.8:

...

Code Block
<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 to 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 specific specify a profile on the command line using the -P parameter:

...

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 module pagesmodel 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.