Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »


This page is a work in progress.

This page is a work in progress. This info box will be removed once complete.

Postgres Repositories Unit tests

Testing Structure

The tests uses the configuration file opensrp-core/src/test/resources/test-applicationContext-opensrp.xml.
This file unlike the runtime loads both Postgres and CouchDb beans, this will to allow the existing unit tests that used Couchdb continue to work without any changes. The CouchDb beans are annotated with the annotation @Primary which means that they are the used even  if there are other beans implementing an interface.

So the tests(unit and integration) thats are implicitly for postgres the units tests qualify the bean by the @Qualifier so that they specify explicitly the bean to be injected i.e in this this case Postgres bean. 

Postgres Repositories Unit Tests


Units tests have been defined that unit test the Postgres repository package org.opensrp.repository.postgres. The repositories unit tests are in the package org.opensrp.repository.postgres
The unit tests use Junit for unit testing and test for various scenarios for each method in the respective repository class being tested. Each of the test extend the class org.opensrp.repository.postgres.BaseRepositoryTest. This class defines tow methods

  • populateDatabase method that cleans and populates the database with seed data before the test starts. Its annotated with Junit  annotation @Before and this runs before each test.
  • getDatabaseScripts abstract method which returns a set of string. Each test must implement this method, the set returned by the implementation should have a set of sql files to be executed before starting each test.


The tests use the seed data in the folder opensrp-core/src/test/resources/test-scripts/. Each script clears any existing data and then populates the test data.

Services Integration Tests

Integration tests were written for services. The tests concentrate on methods with some business logic or have pre or post processing before calling the repositories. 
The services extends org.opensrp.repository.postgres.BaseRepositoryTest so that they are also able to easily apply one or more scripts to populate seed before the tests commence.

With the repositories unit tests and units integration tests regression errors are easily reported early.

  • No labels