Skip to main content

Extending Operator Test Suites

The test framework does not replace your existing test suites that use operators (TestProxy). Those tests keep working next to the test framework, and you can keep maintaining them as before. Use the test framework to extend the suite: write new tests with the test framework, and leave the existing tests as they are.

Converting an existing operator test is optional. Do it only when it adds value, for example when you change the test anyway. The rest of this page explains how to convert a test, if you choose to.

caution

Do not combine operators and the test framework in one test. Both keep their own separate collection of data, which makes the test unclear and confusing. Keep both test suites separate. Your source code can still use operators.

Move the test class​

Test framework tests live in the test-framework module of the component: <component>/test-framework/test/common/src. When you move a test class there, it may still use other classes from the test folder of its original module. In that case, the test-framework module needs a dependency on the test-jar of the original module.

  1. Create a test-jar in the original module by adding this plugin to its pom.xml:

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.4.2</version>
    <executions>
    <execution>
    <goals>
    <goal>test-jar</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
  2. Add a dependency on that test-jar to the custom-dependencies anchorAnchorA marker within generated source code reserved for adding custom logic during re-expansion. in <component>/test-framework/pom.xml:

    <!-- anchor:custom-dependencies:start -->
    <dependency>
    <groupId>${packageName}</groupId>
    <artifactId>${originalModule}</artifactId>
    <version>${project.version}</version>
    <type>test-jar</type>
    </dependency>
    <!-- anchor:custom-dependencies:end -->

Convert the test class​

After the move, the test class still works as before. Convert it in two steps:

  1. Add the @WithTestFramework annotation to the class. As long as the context contains a MockContext, TestContext or TestProxyContext, the operators still mock the complete logic layerLayerLogical separation of functionality within a single system/application, focused on code organization..
  2. Replace that context with Context.emptyContext(). From this point on, the test uses the test framework.

What changes for the test​

  • All changes go through the agent: every database change now goes through the operator or local agent of the data elementData Element (DataElement). A fundamental data concept or entity within an application's domain, acting as an anthropomorphic translation of a real-life object or concept.. All validations are therefore active.
  • Test data must be valid: create test data that satisfies all validations, for example with test data factories. Alternatively, mock the bean to return the result your test needs.
  • Fully mocked tests stay fast: if the logic layerLayerLogical separation of functionality within a single system/application, focused on code organization. is completely mocked and the test never reaches the in-memory database, the database does not start.