Package com.vaadin.browserless.quarkus
Class QuarkusBrowserlessTest
java.lang.Object
com.vaadin.browserless.BaseBrowserlessTest
com.vaadin.browserless.quarkus.QuarkusBrowserlessTest
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidTears down mocked Vaadin.protected voidCreate mocked Vaadin core obects, such as session, servlet populated with Routes, UI etc.Gets the services implementations to be used to initialized VaadinLookup.protected final StringGets the name of the Test Engine that is able to run the base class implementation.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, scanPackages, scanTesters, test, testMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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
Description copied from class:BaseBrowserlessTestGets 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:
testingEnginein classBaseBrowserlessTest- Returns:
- name of the Test Engine.
-
initVaadinEnvironment
@BeforeEach protected void initVaadinEnvironment()Description copied from class:BaseBrowserlessTestCreate mocked Vaadin core obects, such as session, servlet populated with Routes, UI etc. for testing and find testers for the components.- Overrides:
initVaadinEnvironmentin classBaseBrowserlessTest
-
cleanVaadinEnvironment
@AfterEach protected void cleanVaadinEnvironment()Description copied from class:BaseBrowserlessTestTears down mocked Vaadin.- Overrides:
cleanVaadinEnvironmentin classBaseBrowserlessTest
-
lookupServices
Description copied from class:BaseBrowserlessTestGets the services implementations to be used to initialized VaadinLookup. Default implementation returns an empty Set. Override this method to provide custom Vaadin services, such asInstantiatorFactory,ResourceProvider, etc.- Overrides:
lookupServicesin classBaseBrowserlessTest- Returns:
- set of services implementation classes, never null.
-