Versions Compared

Key

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


Info
titleThis 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 CouchDb continue to work run without any changes. The CouchDb beans are annotated with the annotation @Primary which means that they are the used even  even if there are other beans implementing an interface.

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

...


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 in the test folder
The unit tests use Junit JUnit(SpringJUnit4ClassRunner) 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  This class defines tow two methods

  • populateDatabase method that cleans and populates the database with seed data before the test starts. Its annotated with Junit  JUnit  annotation @Before and this so that it runs before each test.
  • getDatabaseScripts abstract method which returns a set of stringstrings. 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 created by tests in the folder opensrp-core/src/test/resources/test-scripts/. Each script clears any existing data and then populates the test data.

...