Package 

Class UIUnitTest

  • All Implemented Interfaces:
    com.vaadin.testbench.unit.TesterWrappers

    
    public abstract class UIUnitTest
    extends BaseUIUnitTest implements TesterWrappers
                        

    Base JUnit 5 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

    
    @ViewPackages(classes = {CartView.class, CheckoutView.class})
    class CartViewTest extends UIUnitTest {
    }
    
    @ViewPackages(packages = {"com.example.shop.cart", "com.example.security"})
    class CartViewTest extends UIUnitTest {
    }
    
    @ViewPackages(
       classes = {CartView.class, CheckoutView.class},
       packages = {"com.example.security"}
    )
    class CartViewTest extends UIUnitTest {
    }
    </pre>
    
    Set up of Vaadin environment is performed before each test by {
    #initVaadinEnvironment()} method, and will be executed before
    {@BeforeEach} methods defined in subclasses. At the same way, cleanup
    tasks operated by {#cleanVaadinEnvironment()} are executed after each
    test, and after all {@AfterEach} annotated methods in subclasses.
    
    Usually, it is not necessary to override {#initVaadinEnvironment()} or
    {#cleanVaadinEnvironment()} methods, but if this is done it is
    mandatory to add the {@BeforeEach} and {@AfterEach} annotations
    in the subclass, in order to have hooks handled by testing framework.
    
    A use case for overriding {#initVaadinEnvironment()} is to provide
    custom Flow service implementations supported by {
    com.vaadin.flow.di.Lookup} SPI. Implementations can be provided overriding
    {#initVaadinEnvironment()} and passing to super implementation the
    service classes that should be initialized during setup.
    
    <pre>
    {
    &#64;BeforeEach
    &#64;Override
    void initVaadinEnvironment() {
        super.initVaadinEnvironment(CustomInstantiatorFactory.class);
    }
    }
    </pre>
    <p/>
    To get a graphical ascii representation of the UI tree on failure add the
    annotation {@ExtendWith(TreeOnFailureExtension.class)} to the test
    class.
    
    ViewPackages
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      • Methods inherited from class com.vaadin.testbench.unit.BaseUIUnitTest

        $, $view, fireShortcut, getCurrentView, navigate, test
      • Methods inherited from class 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail