Class QuarkusBrowserlessTest

java.lang.Object
com.vaadin.browserless.BaseBrowserlessTest
com.vaadin.browserless.quarkus.QuarkusBrowserlessTest
All Implemented Interfaces:
TesterWrappers

public abstract class QuarkusBrowserlessTest extends BaseBrowserlessTest implements TesterWrappers
Base JUnit 5+ class for browserless testing of applications based on Quarkus stack. This class sets up a mock Vaadin Quarkus environment, so that views and components built upon dependency injection and AOP can be correctly be handled during unit testing. A CDI container is required for the test to work. With Quarkus testing framework, setting up the CDI environment can be achieved by annotating the test class with @QuarkusTest. The annotation registers a JUnit extension that deploys and starts the whole application, including the initialization of the CDI container. The drawback of this approach is that the application also starts the HTTP server, effectively initializing the entire Vaadin application. Tests are still performed in a mocked environment, but it is not possible out-of-the-box to run them in isolation, with only the components needed by the test.
 {
     @QuarkusTest
     class MainViewTest extends QuarkusBrowserlessTest {

         @Test
         void accessView() {
             MainView mainView = navigate(MainView.class);
             Assertions.assertNotNull(mainView);
         }
     }
 }
 
An alternative since Quarkus 3.2 could be the usage of (@QuarkusComponentTest annotation), that targets testing of single CDI components. However, this kind of tests require a lot of manual setup, because every component involved in the test must be explicitly defined (including Vaadin Quarkus extension classes, since deployment augmentation is not performed). In addition, beans may still be removed by the CDI container because considered unused or not found because of missing bean defining annotations. For the above reasons, currently, using @QuarkusComponentTest is not recommended.

This class extends BaseBrowserlessTest directly (not BrowserlessTest) to avoid inheriting @ExtendWith(BrowserlessTestExtension.class). The Vaadin environment lifecycle is instead managed by @BeforeEach/@AfterEach methods, which JUnit 5 fires after all extension beforeEach callbacks — in particular after QuarkusTestExtension.beforeEach(), which activates the CDI request scope and applies @TestSecurity identities.