Class BaseUIUnitTest
- Direct Known Subclasses:
UIUnit4Test,UIUnitTest
ViewPackages annotation. If the annotation is not
present a full classpath scan is performed
For internal use only. May be renamed or removed in a future release.- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends Component>
ComponentQuery<T> Gets a query object for finding a component inside the UI<T extends Component>
ComponentQuery<T> Gets a query object for finding a component nested inside the given component.<T extends Component>
ComponentQuery<T> Gets a query object for finding a component inside the current viewprotected voidTears down mocked Vaadin.protected com.vaadin.testbench.unit.internal.Routesprotected static com.vaadin.testbench.unit.internal.RoutesdiscoverRoutes(Set<String> packageNames) Discover and return Routes for mocked Vaadin core system.voidfireShortcut(Key key, KeyModifier... modifiers) Simulates a keyboard shortcut performed on the browser.Get the current view instance that is shown on the ui.protected voidprotected voidCreate mocked Vaadin core obects, such as session, servlet populated with Routes, UI etc.Gets the services implementations to be used to initialized VaadinLookup.<T extends Component>
TNavigate to the given view class if it is registered.<C,T extends Component & HasUrlParameter<C>>
TNavigate to view with url parameter.<T extends Component>
TNavigate to view corresponding to the given navigation target with the specified parameters.<T extends Component>
TNavigate to given location string.protected static voidSimulates a server round-trip, flushing pending component changes.protected final booleanProcesses all pending Signals tasks with a default max wait time of 100 milliseconds.protected final booleanrunPendingSignalsTasks(long maxWaitTime, TimeUnit unit) Processes all pending Signals tasks, waiting up to the specified timeout for tasks to arrive.protected voidScan testers and populate testers map with them.<T extends ComponentTester<Y>,Y extends Component>
TWrap component in given ComponentTester.<T extends ComponentTester<Y>,Y extends Component>
Ttest(Y component) Wrap component with ComponentTester best matching component type.protected abstract StringGets the name of the Test Engine that is able to run the base class implementation.
-
Field Details
-
testers
-
scanned
-
-
Constructor Details
-
BaseUIUnitTest
public BaseUIUnitTest()
-
-
Method Details
-
discoverRoutes
protected com.vaadin.testbench.unit.internal.Routes discoverRoutes() -
discoverRoutes
Discover and return Routes for mocked Vaadin core system.- Returns:
- Routes
- See Also:
-
initVaadinEnvironment
protected void initVaadinEnvironment()Create mocked Vaadin core obects, such as session, servlet populated with Routes, UI etc. for testing and find testers for the components. -
initSignalsSupport
protected void initSignalsSupport() -
scanTesters
protected void scanTesters()Scan testers and populate testers map with them. The test method can find appropriate test based on testers map.- See Also:
-
cleanVaadinEnvironment
protected void cleanVaadinEnvironment()Tears down mocked Vaadin. -
lookupServices
Gets 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.- Returns:
- set of services implementation classes, never null.
-
fireShortcut
Simulates a keyboard shortcut performed on the browser.- Parameters:
key- Primary key of the shortcut. This must not be aKeyModifier.modifiers- Key modifiers. Can be empty.
-
getCurrentView
Get the current view instance that is shown on the ui.- Returns:
- current view
-
test
Wrap component with ComponentTester best matching component type.- Type Parameters:
T- tester typeY- component type- Parameters:
component- component to get test wrapper for- Returns:
- component in wrapper with test helpers
-
test
Wrap component in given ComponentTester.- Type Parameters:
T- tester typeY- component type- Parameters:
tester- test wrapper to usecomponent- component to wrap- Returns:
- initialized test wrapper for component
-
$
Gets a query object for finding a component inside the UI- Type Parameters:
T- the type of the component(s) to search for- Parameters:
componentType- the type of the component(s) to search for- Returns:
- a query object for finding components
-
$
Gets a query object for finding a component nested inside the given component.- Type Parameters:
T- the type of the component(s) to search for- Parameters:
componentType- the type of the component(s) to search forfromThis- component used as starting element for search.- Returns:
- a query object for finding components
-
$view
Gets a query object for finding a component inside the current view- Type Parameters:
T- the type of the component(s) to search for- Parameters:
componentType- the type of the component(s) to search for- Returns:
- a query object for finding components
-
roundTrip
protected static void roundTrip()Simulates a server round-trip, flushing pending component changes. -
runPendingSignalsTasks
protected final boolean runPendingSignalsTasks()Processes all pending Signals tasks with a default max wait time of 100 milliseconds. This is a convenience method for tests that need to wait for asynchronous Signal effects to complete.When Signals are triggered from background threads or non-UI contexts, their effects are enqueued to simulate asynchronous processing. This method allows tests to flush and execute all such pending tasks synchronously, ensuring deterministic behavior in unit tests.
If any
VaadinSessionlock is held by the current thread, it is temporarily released during the wait to allow background threads to acquire the lock and enqueue tasks.If Signals support is not enabled (via the
FLOW_FULLSTACK_SIGNALSfeature flag), this method does nothing.- Returns:
trueif any pending Signals tasks were processed.- See Also:
-
runPendingSignalsTasks
Processes all pending Signals tasks, waiting up to the specified timeout for tasks to arrive. This method is essential for testing asynchronous Signal effects triggered from background threads or non-UI contexts.When Signals are triggered from background threads or non-UI contexts, their effects are enqueued to simulate asynchronous processing. This method allows tests to flush and execute all such pending tasks synchronously, ensuring deterministic behavior in unit tests.
The timeout applies only to waiting for the first task to arrive. Once the first task is found, all remaining tasks in the queue are processed immediately without additional waiting. If any
VaadinSessionlock is held by the current thread, it is temporarily released during the wait to allow background threads to acquire the lock and enqueue tasks.If Signals support is not enabled (via the
FLOW_FULLSTACK_SIGNALSfeature flag), this method does nothing.- Parameters:
maxWaitTime- the maximum time to wait for the first task to arrive in the given time unit. If <= 0, returns immediately if no tasks are available.unit- the time unit of the timeout value- Returns:
trueif any pending Signals tasks were processed.- See Also:
-
testingEngine
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.- Returns:
- name of the Test Engine.
-