| name | ui-testing |
| description | TestFX patterns for JavaFX controller testing in Xeres including FXML loading with controller factories, mocking reactive clients, and user interaction testing. |
UI Testing Patterns for Xeres
TestFX Setup
UI tests use TestFX with both ApplicationExtension and MockitoExtension:
@ExtendWith({ApplicationExtension.class, MockitoExtension.class})
class ContactViewControllerTest
{
@Mock
private ProfileClient profileClient;
@InjectMocks
private ContactViewController controller;
@Test
void testFxmlLoading() throws IOException
{
FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/contact/contact_view.fxml"));
loader.setControllerFactory(_ -> controller);
Parent root = loader.load();
assertThat(root).isNotNull();
}
}
FXTest Base Class
For tests requiring JavaFX initialization, extend FXTest:
class SomeJavaFXTest extends FXTest
{
@Test
void test
javafx components()
{
}
}
FXML Loading Pattern
@Test
void initialize_ShouldLoadContacts() throws IOException
{
FXMLLoader loader = new FXMLLoader(
getClass().getResource("/view/contact/contact_view.fxml")
);
loader.setControllerFactory(javaClass -> controller);
controller.initialize();
assertThat(controller.getContactTreeTableView()).isNotNull();
}
Testing User Interactions
@Test
void clickButton_ShouldTriggerAction()
{
var button = lookup("#saveButton").query();
clickOn(button);
verify(profileClient).save(any(Profile.class));
}
Mocking Reactive Clients
For WebClient-based clients returning Mono:
when(profileClient.findById(anyLong()))
.
thenReturn(Mono.just(testProfile));
See Also
junit-testing skill for basic testing patterns
javafx-patterns skill for controller structure