Skip to content

Latest commit

 

History

History
87 lines (62 loc) · 3.14 KB

integration_tests_mw.adoc

File metadata and controls

87 lines (62 loc) · 3.14 KB

Middleware Integration Tests

Middleware integration tests run in a fully functional Spring container connected to the database. In such tests, you can run code on all layers of the middleware, from services down to ORM.

In order to configure and start the middleware Spring container in tests, create a subclass of the com.haulmont.cuba.testsupport.TestContainer base class in your project and use its instance in tests as a JUnit Rule.

Below is an example of the container class and an integration test for the Sales project described in [quick_start]. All classes must be located in the test directory of the core module.

link:../../../../source/development/testing_3.java[role=include]

An example of the custom test-app.properties file:

link:../../../../source/development/testing_11.properties[role=include]

We recommend using a separate test database, which can be created, for example, by the following Gradle task defined in build.gradle:

link:../../../../source/development/testing_4.groovy[role=include]

The test container should be used in test classes as a JUnit rule specified by the @ClassRule annotation:

link:../../../../source/development/testing_5.java[role=include]
Useful container methods

The TestContainer class contains the following methods that can be used in the test code (see the CustomerLoadTest example above):

  • persistence() – returns the reference to the Persistence interface.

  • metadata() – returns the reference to the Metadata interface.

  • deleteRecord() – this set of overloaded methods is aimed to be used in @After methods to clean up the database after tests.

Logging

The test container sets up logging according to the test-logback.xml file provided by the platform. It is contained in the root of the cuba-core-tests artifact.

If you want to configure logging levels for your tests, do the following:

  • Copy test-logback.xml from the platform artifact to the root of the test folder of your project’s core module, e.g. as my-test-logback.xml.

  • Configure appenders and loggers in my-test-logback.xml.

  • Add a static initializer to your test container to specify the location of your logback configuration file in the logback.configurationFile system property:

    link:../../../../source/development/testing_9.java[role=include]
Additional Data Stores

If your project uses additional data stores, you should create corresponding JDBC data sources in your test container. For example, if you have mydb datastore which is a PostgreSQL database, add the following method to the test container class:

link:../../../../source/development/testing_10.java[role=include]

Also, if the additional database type is different from the main one, you should add its driver as the testRuntime dependency to the core module in build.gradle, for example:

link:../../../../source/development/testing_12.groovy[role=include]