com.vaadin.testbench.unit.
Class UIUnit4Test
All Implemented Interfaces:
Direct Known Subclasses:
Base JUnit 4 class for UI unit tests.
The class automatically scans classpath for routes and error views.
Subclasses should typically restrict classpath scanning to a specific
packages for faster bootstrap, by using ViewPackages
annotation. If
the annotation is not present a full classpath scan is performed
{@code
@ViewPackages(classes = {CartView.class, CheckoutView.class})
public class CartViewTest extends UIUnit4Test {
}
@ViewPackages(packages = {"com.example.shop.cart", "com.example.security"})
public class CartViewTest extends UIUnit4Test {
}
@ViewPackages(
classes = {CartView.class, CheckoutView.class},
packages = {"com.example.security"}
)
public class CartViewTest extends UIUnit4Test {
}
</pre>
Set up of Vaadin environment is performed before each test by {@link
#initVaadinEnvironment()} method, and will be executed before {@code @Before}
methods defined in subclasses. At the same way, cleanup tasks operated by
{@link #cleanVaadinEnvironment()} are executed after each test, and after all
{@code @After} annotated methods in subclasses.
Custom Flow service implementations supported by {@link
com.vaadin.flow.di.Lookup} SPI can be provided overriding {@link
#initVaadinEnvironment()} and passing to super implementation the service
classes that should be initialized during setup.
<pre>
{@code
@Override
public void initVaadinEnvironment() {
super.initVaadinEnvironment(CustomInstantiatorFactory.class);
}
}
</pre>
<p/>
To get a graphical ascii representation of the UI tree on failure override
the {@link #printTree()} method to return true.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Map<Class<?>,
Class<? extends ComponentTester>> org.junit.rules.TestRule
-
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 view
protected void
void
fireShortcut
(Key key, KeyModifier... modifiers) Simulates a keyboard shortcut performed on the browser.
Get the current view instance that is shown on the ui.
void
Gets the services implementations to be used to initialized Vaadin
Lookup
.<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.
boolean
Override to return true to get component tree output into log on test failure.
protected static void
Simulates a server round-trip, flushing pending component changes.
<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 final String
Gets the name of the Test Engine that is able to run the base class implementation.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.vaadin.testbench.unit.TesterWrappers
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
-
Field Details
-
treeOnFailure
public org.junit.rules.TestRule treeOnFailure -
testers
-
scanned
-
-
Constructor Details
-
UIUnit4Test
public UIUnit4Test()
-
-
Method Details
-
printTree
public boolean printTree()Override to return true to get component tree output into log on test failure.
Returns:
true
to print component tree -
initVaadinEnvironment
public void initVaadinEnvironment() -
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.
-
cleanVaadinEnvironment
protected void cleanVaadinEnvironment() -
lookupServices
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 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 typeParameters:
component
- component to get test wrapper forReturns:
component in wrapper with test helpers
-
test
Wrap component in given ComponentTester.
Type Parameters:
T
- tester typeY
- component typeParameters:
tester
- test wrapper to usecomponent
- component to wrapReturns:
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 forParameters:
componentType
- the type of the component(s) to search forReturns:
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 forParameters:
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 forParameters:
componentType
- the type of the component(s) to search forReturns:
a query object for finding components
-
roundTrip
protected static void roundTrip()Simulates a server round-trip, flushing pending component changes.
-