Skip to main content

Multiple models with @UseModel

It is possible to have more than 1 test model per test class.

By default, the method with name baseModel() will be used. To use another model in a test, annotate that test with @UseModel and pass the method name of the alternative specification method.

  @TestModel(select = "testComp::City")
Spec baseModel() {
return component("testComp",
dataElement("City",
set("packageName", "net.demo.cities")));
}

@TestModel(select = "testComp::City")
Spec linkFieldsModel() {
return component("testComp",
dataElement("Country"),
dataElement("City",
field("country: Country[Ln01]")));
}

@Test
void test_base(TestExpansion<DataElementComposite> expansion) {
expansion.assertThatExpander().baseContent().matchesTemplate();
}

@Test
@UseModel("linkFieldsModel")
void test_anchor_fields_linkFields(TestExpansion<DataElementComposite> expansion) {
expansion
.assertThatExpander().anchor("fields")
.matchesTemplate();
}