There are 2 high-level types of integration tests in the Liquibase codebase.
- Database Integration Tests
- The first type validates common/shared database functionality.
- The second type validates specific database functionality across supported databases.
- Interface/Integration Integration Tests
The following sections discuss the two major types of tests and the additional subsets of tests for databases.
Database Integration Tests
Tests for functionality that is the same across all databases should go in the liquibase-integration-tests/src/test/java/liquibase/dbtest/AbstractIntegrationTest
class. This will ensure that the integration test is executed against all database types.
For each database we support, there is also a subclass of AbstractIntegrationTest.java
in a sub-package. Here are the locations of the current integration test classes for each supported database.
All integration tests are standard JUnit classes, so new tests are created by adding new methods with the @Test annotation.
Common/Shared Integration Tests
AbstractIntegrationTest.java
The base java file liquibase-integration-tests/src/test/java/liquibase/dbtest/AbstractIntegrationTest.java
defines the standard tests that get executed against our supported databases.
This is a large test suite that does everything from testing specific methods on the Database interface to running changelogs of different formats through the entire Liquibase process.
Database Platform | Database Type | Integration Test – Main Java Class Location | Test Count |
---|---|---|---|
All | All | liquibase-integration-tests/src/test /java/liquibase/dbtest/Abstract IntegrationTest.java |
27 |
Example test method:
public abstract class AbstractIntegrationTest { .... @Test public void testGenerateChangeLogWithNoChanges() throws Exception { assumeNotNull(this.getDatabase()); runCompleteChangeLog(); DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(database, database, new CompareControl()); DiffToChangeLog changeLogWriter = new DiffToChangeLog(diffResult, new DiffOutputControl(false, false, false, null)); List<ChangeSet> changeSets = changeLogWriter.generateChangeSets(); assertEquals("generating two change logs without any changes in between should result in an empty generated " + "differential change set.", 0, changeSets.size()); } }
The database class-level field referenced in the test will be the database under test with the live connection to the database. As each subclass of of AbstractIntegrationTest is ran, it will set up that object based on the information in liquibase.integrationtest.properties.
If the connection cannot be made, ALL tests in the subclass will be skipped.
Using that field, you can interact with any of the Liquibase classes you need to implement your test.
Explanation of a Common/Shared Integration Test
See the test method, testRerunDiffChangeLog
, completing all of these steps.
- View steps on GitHub
- View changelogs for all of the integration tests
- View each changeset is an integration test
Example Tests | Liquibase Command | See the example |
---|---|---|
To run a changelog file, use the runChangeLogFile() command – this changelog can be in any changelog format on line 365. |
update | AbstractIntegrationTest.java#L365 |
Snapshot the database after applying the changelog on line 669. |
snapshot | AbstractIntegrationTest.java#L669 |
You can see how we do a diffChangeLog with an empty database to re-create what was in the original changelog on lines 726-734. |
diffChangeLog | AbstractIntegrationTest.java#L726 |
You can see how we execute the generated changelog on lines 736-742. |
update | AbstractIntegrationTest.java#L736 |
You can see how we validate the results by comparing the snapshot from the original update with the one we from the just did from the generated changelog on lines 744-749. |
N/A | AbstractIntegrationTest.java#L744 |