Class QuarkusBrowserlessTest

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

public abstract class QuarkusBrowserlessTest extends com.vaadin.browserless.BaseBrowserlessTest implements com.vaadin.browserless.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.

  • Field Summary

    Fields inherited from class com.vaadin.browserless.BaseBrowserlessTest

    scanned, testers
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
    protected void
     
    protected Set<Class<?>>
     
    protected final String
     

    Methods inherited from class com.vaadin.browserless.BaseBrowserlessTest

    $, $, $view, discoverRoutes, discoverRoutes, find, find, findInView, fireShortcut, getCurrentView, initSignalsSupport, internalWrap, internalWrap, navigate, navigate, navigate, navigate, roundTrip, runPendingSignalsTasks, runPendingSignalsTasks, scanForTesters, scanPackages, scanTesters, test, test

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.browserless.TesterWrappers

    popoverFor, popoverFor, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test, test
  • Constructor Details

    • QuarkusBrowserlessTest

      public QuarkusBrowserlessTest()
  • Method Details

    • testingEngine

      protected final String testingEngine()
      Specified by:
      testingEngine in class com.vaadin.browserless.BaseBrowserlessTest
    • initVaadinEnvironment

      @BeforeEach protected void initVaadinEnvironment()
      Overrides:
      initVaadinEnvironment in class com.vaadin.browserless.BaseBrowserlessTest
    • cleanVaadinEnvironment

      @AfterEach protected void cleanVaadinEnvironment()
      Overrides:
      cleanVaadinEnvironment in class com.vaadin.browserless.BaseBrowserlessTest
    • lookupServices

      protected Set<Class<?>> lookupServices()
      Overrides:
      lookupServices in class com.vaadin.browserless.BaseBrowserlessTest