Skip to content

Making use of the shared test suite

Paul Schaub edited this page Jan 31, 2023 · 1 revision

The sop-java module provides some generalized tests which check the behaviour of downstream implementations against the specification.
These tests are published as a test-fixtures jar file. To my knowledge, only Gradle-based builds can make sense of those yet.

To make use of these tests, you need to do the following:
In your implementations build.gradle file add the following line to the dependencies section:

    testImplementation(testFixtures("org.pgpainless:sop-java:<version>"))

Next, you need to create a custom implementation of the sop.testsuite.SOPInstanceFactory class.

package org.example.sop;

[...]

public class ExampleSOPInstanceFactory extends SOPInstanceFactory {

    @Override
    public Map<String, SOP> provideSOPInstances() {
        Map<String, SOP> instances = new HashMap<>();
        instances.put("ExampleSOP", new ExampleSOP()); // One or more instances of your SOP implementation
        return instances;
    }
}

The sop-java test suite makes use of an environment variable test.implementation to determine the SOPInstanceFactory class to use. Add the following line to the test section of your build.gradle file to set your own factory class:

test {
    useJUnitPlatform()

    // FQDN of your SOPInstanceFactory class
    environment("test.implementation", "org.example.sop.ExampleSOPInstanceFactory")
}

Lastly in your modules src/test/ source directory you need to extend the concrete test case classes from sop-java/src/testFixtures/java/sop/testsuite/operation/. Your inherited classes can stay empty though. Here is an example of an extension of the ArmorDearmorTest:

package org.example.sop.operation;

import sop.testsuite.operation.ArmorDearmorTest;

public class ExampleArmorDearmorTest extends ArmorDearmorTest {

}

For reference / inspiration, check out how pgpainless-sop made use of the suite.

Clone this wiki locally