Set Up Browserless Tests with Quarkus
Use this guide for an existing Quarkus Flow application.
Use QuarkusBrowserlessTest and Quarkus test profiles throughout this setup.
For a Java EE application using Vaadin CDI and Weld, use the separate CDI setup.
Add Dependencies
With the Vaadin BOM imported, add these test dependencies to your pom.xml file:
Source code
pom.xml
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>browserless-test-junit6</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>browserless-test-quarkus</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>Create and Configure the Test
Create this view and put its test in the same Java package under src/test/java:
Source code
HelloWorldView.java
HelloWorldView.java@Route("")
public class HelloWorldView extends HorizontalLayout {
TextField name;
Button sayHello;
public HelloWorldView() {
name = new TextField("Your name");
sayHello = new Button("Say hello");
sayHello.addClickListener(e -> {
Notification.show("Hello " + name.getValue());
});
add(name, sayHello);
}
}Source code
Quarkus Test Example
@QuarkusTest
class ViewTest extends QuarkusBrowserlessTest {
@Test
public void setText_clickButton_notificationIsShown() {
final HelloWorldView helloView = navigate(HelloWorldView.class);
test(helloView.name).setValue("Test");
test(helloView.sayHello).click();
Notification notification = find(Notification.class).single();
Assertions.assertEquals("Hello Test", test(notification).getText());
}
}|
Note
|
With @QuarkusTest annotation, the testing framework starts the application and the HTTP server — although it won’t be required for browserless testing. However, QuarkusBrowserlessTest tests are still executed in a mocked environment.
|
A test can be annotated with @TestProfile to reference a specific test configuration. With a test profile you can, for example, override application configuration, provide bean alternatives and custom test resources. Refer to the Quarkus Testing Profiles documentation for additional information.
Source code
Quarkus Testing Profile Example
public class MockServiceProfile implements QuarkusTestProfile {
@Override
public Map<String, String> getConfigOverrides() {
return Collections.singletonMap("app.some.config","value");
}
@Override
public Set<Class<?>> getEnabledAlternatives() {
return Collections.singleton(MockService.class);
}
}
@QuarkusTest
@TestProfile(MockServiceProfile.class)
class ViewTest extends QuarkusBrowserlessTest {
}Run the Test
Run the test from your IDE or with mvn test.
To test protected views, continue with Test View Access Control with Quarkus.
09A26994-97AB-4877-AEB1-717BE02E348D