Skip to main content

Test Data

For some use-cases, you might need to provide DataResources that are only applicable for tests or a specific test. The data in question should only be available during tests and not be part of the final product.

Expanders-assert provides 2 methods:

  • Add a DataResource in the test resources directory.
  • Add test data using the @TestData annotation.

Test Resources

You can add dataResource files in the src/test/resources directory. The test framework will pick up these files and provide them during tests.

The benefit of this approach is that the data is then defined for all tests. This can be useful when using a ModelSpecTemplate that requires some additional elements to be provided.

It can also help you when you wish to write tests for known use-cases, but the data should be provided by another expansion-resource. In this case you can provide the same data during tests, but avoid the coupling at runtime.

TestData methods

Test Data can also be provided in the Test class itself through methods annotated with @TestData. The method should return a Spec instance or a list of Spec instances.

@ExpanderTest
class MyExpanderTest {

@TestData
Spec technologyData() {
return technology("MY_TECHNOLOGY");
}

@TestData
List<Spec> layerData() {
return List.of(
layerType("BASE_LAYER"),
layerType("TOP_LAYER"));
}

}

The data defined in this method will only be available within the Test class. This allows more freedom to tailor the test data to your specific test-cases.