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.

  • Constructor Details

    • QuarkusBrowserlessTest

      public QuarkusBrowserlessTest()
  • Method Details

    • testingEngine

      protected final String testingEngine()
      Description copied from class: BaseBrowserlessTest
      Gets the name of the Test Engine that is able to run the base class implementation. The Test Engine name is reported in the exception thrown when the Vaadin environment is not set up correctly.
      Specified by:
      testingEngine in class BaseBrowserlessTest
      Returns:
      name of the Test Engine.
    • initVaadinEnvironment

      @BeforeEach protected void initVaadinEnvironment()
      Description copied from class: BaseBrowserlessTest
      Create mocked Vaadin core obects, such as session, servlet populated with Routes, UI etc. for testing and find testers for the components.
      Overrides:
      initVaadinEnvironment in class BaseBrowserlessTest
    • cleanVaadinEnvironment

      @AfterEach protected void cleanVaadinEnvironment()
      Description copied from class: BaseBrowserlessTest
      Tears down mocked Vaadin.
      Overrides:
      cleanVaadinEnvironment in class BaseBrowserlessTest
    • lookupServices

      protected Set<Class<?>> lookupServices()
      Description copied from class: BaseBrowserlessTest
      Gets the services implementations to be used to initialized Vaadin Lookup. Default implementation returns an empty Set. Override this method to provide custom Vaadin services, such as InstantiatorFactory, ResourceProvider, etc.
      Overrides:
      lookupServices in class BaseBrowserlessTest
      Returns:
      set of services implementation classes, never null.