Conformance tests

The GeoAPI conformance tests are currently written in Java as JUnit tests, but implementations in other languages can be tested using for example the Java-Python bridge. GeoAPI tests provide three kinds of Java classes:

The test cases and validators are grouped in util, metadata, referencing and geometry packages. A graphical JUnit runner is also provided in the runner package. That JUnit runner is designed specifically for the geoapi-conformance test suite, and provides more information than common runners (for example which factories were used for each test).

Running all pre-defined tests

The easiest way to test an implementation is to add the following class in the implementation test package. There is nothing else needed if all factories are registered in the META-INF/services/ directory and all objects are fully implemented:

Java code example

package org.myproject;

import org.opengis.test.TestSuite

/**
* Executes all GeoAPI tests using the factories registered in the META-INF/services directory.
* Every GeoAPI objects to be tested are assumed fully implemented. The implementation accuracy
* is assumed good enough for the default tolerance thresholds.
*/
public class GeoapiTest extends TestSuite {
}

Writing custom tests

Implementers can either write their own JUnit tests, or extend some of the existing implementations. With the latter approach, implementers can override the existing test methods for finer control on the tests being executed. In every cases, implementers can use the static methods for testing their implementation consistency. For example an implementer can test the validity of his Coordinate Reference System objects and related objects in a test suite like below:

Java code example

package org.myproject;

import org.junit.*;
import static org.opengis.test.Validators.*;

public class MyTests {
    @Test
    public void testMyCRS() {
        CoordinateReferenceSystem crs = ...
        validate(crs);

        MathTransform transform = ...
        validate(transform);
    }
}

Validators are thread-safe except for the configuration phase (which is optional and usually executed only once before the tests begin). Validators test the logical consistency of their argument. For example if given a chain of concatenated transforms, validate(object) will ensure that the source dimension of a transformation step is equals to the target dimension of the previous step. Dependencies are traversed recursively, for example validating a CoordinateReferenceSystem object implies validating its CoordinateSystem and Datum attributes.