Class BrowserlessTest
- All Implemented Interfaces:
TesterWrappers
ViewPackages annotation. If the
annotation is not present, a full classpath scan is performed.
@ViewPackages(classes = { CartView.class, CheckoutView.class })
class CartViewTest extends BrowserlessTest {
}
@ViewPackages(packages = { "com.example.shop.cart", "com.example.security" })
class CartViewTest extends BrowserlessTest {
}
@ViewPackages(classes = { CartView.class, CheckoutView.class }, packages = {
"com.example.security" })
class CartViewTest extends BrowserlessTest {
}
The Vaadin environment is set up before each test by the
initVaadinEnvironment() @BeforeEach method and cleaned up
afterwards by the cleanVaadinEnvironment() @AfterEach
method. Being instance lifecycle methods (rather than extension callbacks),
they run after all JUnit 5 extension beforeEach callbacks,
so the test can be combined with extensions that MockVaadin depends
on ? for example a CDI container started by weld-junit5's
@EnableAutoWeld, whose BeanManagerProvider must be in place
before MockVaadin.setup() runs.
Usually it is not necessary to override initVaadinEnvironment() or
cleanVaadinEnvironment(), but if it is done then the override must
keep the @BeforeEach/@AfterEach annotation so the hook is
still handled by the testing framework. A common reason to override
initVaadinEnvironment() is to perform a custom
MockVaadin.setup() ? for instance to register a CDI-aware servlet:
@BeforeEach
@Override
protected void initVaadinEnvironment() {
scanTesters();
MockVaadin.setup(MockedUI::new, cdiVaadinServlet, lookupServices());
}
To provide custom Flow service implementations via the
Lookup SPI, override BaseBrowserlessTest.lookupServices():
@Override
protected Set<Class<?>> lookupServices() {
return Set.of(CustomInstantiatorFactory.class);
}
This class only supports the default per-method lifecycle. Tests that need a
single Vaadin environment shared across all methods in the class should not
extend it; instead register a BrowserlessClassExtension and, if the
testing DSL is wanted directly on the test class, implement
TesterWrappers (and optionally
Locators):
@ViewPackages(classes = MyView.class)
class MyStatefulTest implements TesterWrappers {
@RegisterExtension
static BrowserlessClassExtension ext = new BrowserlessClassExtension();
}
To get a graphical ASCII representation of the UI tree on failure, add
@ExtendWith(TreeOnFailureExtension.class) to the test class.
- See Also:
-
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.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, lookupServices, 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, test, test
-
Constructor Details
-
BrowserlessTest
public BrowserlessTest()
-
-
Method Details
-
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
-
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.
-