Creates Karibu unit tests for Vaadin views.
This skill inherits all available tools. When active, it can use any tool Claude has access to.
templates/ExampleViewTest.javaCreate Karibu unit tests for Vaadin views. Karibu Testing allows server-side testing of Vaadin components without a browser.
Use the KaribuTesting MCP server for documentation and code generation.
Create test data using Flyway migrations in src/test/resources/db/migration.
| Approach | Location | Purpose |
|---|---|---|
| Flyway migration | src/test/resources/db/migration/V*.sql | Populate test data |
| Manual cleanup | @AfterEach method | Remove test-created data |
| Class | Purpose |
|---|---|
| com.github.mvysny.kaributesting.v10.LocatorJ | Find components |
| com.github.mvysny.kaributesting.v10.GridKt | Grid assertions and interactions |
| com.github.mvysny.kaributesting.v10.NotificationsKt | Notification assertions |
| com.github.mvysny.kaributesting.v10.pro.ConfirmDialogKt | ConfirmDialog interactions |
Use templates/ExampleViewTest.java as the test class structure.
UI.getCurrent().
navigate(PersonView .class);
// Find by type
var grid = _get(Grid.class);
var button = _get(Button.class, spec -> spec.withCaption("Save"));
var textField = _get(TextField.class, spec -> spec.withLabel("Name"));
// Find all matching
List<Button> buttons = _find(Button.class);
// Get grid size
assertThat(GridKt._size(grid)).
isEqualTo(100);
// Get selected items
Set<PersonRecord> selected = grid.getSelectedItems();
// Select a row
GridKt.
_selectRow(grid, 0);
// Get cell component (for action buttons)
GridKt.
_getCellComponent(grid, 0,"actions")
.
getChildren()
.
filter(Button .class::isInstance)
.
findFirst()
.
map(Button .class::cast)
.
ifPresent(Button::click);
// Get cell value
String name = GridKt._getFormattedRow(grid, 0).get("name");
// Set field values
_get(TextField .class, spec ->spec.
withLabel("Name")).
_setValue("John");
_get(ComboBox .class, spec ->spec.
withLabel("Country")).
_setValue(country);
_get(DatePicker .class, spec ->spec.
withLabel("Birth Date")).
_setValue(LocalDate.of(1990, 1,1));
// Click button
_get(Button .class, spec ->spec.
withCaption("Save")).
_click();
// Expect notification
expectNotifications("Record saved successfully");
// Assert no notifications
assertThat(NotificationsKt.getNotifications()).
isEmpty();
// Click confirm in dialog
ConfirmDialogKt._fireConfirm(_get(ConfirmDialog.class));
// Click cancel
ConfirmDialogKt.
_fireCancel(_get(ConfirmDialog.class));
Use AssertJ or Karibu Testing assertions:
| Assertion Type | Example |
|---|---|
| Grid size | assertThat(GridKt._size(grid)).isEqualTo(10) |
| Component visible | assertThat(button.isVisible()).isTrue() |
| Component enabled | assertThat(button.isEnabled()).isTrue() |
| Field value | assertThat(textField.getValue()).isEqualTo("x") |
| Collection size | assertThat(items).hasSize(5) |
| Notifications | expectNotifications("Success") |