Class BaseUIUnitTest

java.lang.Object
com.vaadin.testbench.unit.BaseUIUnitTest
Direct Known Subclasses:
UIUnit4Test

public abstract class BaseUIUnitTest extends Object
Base class for UI unit tests. Provides methods to set up and clean a mocked Vaadin environment. The class allows scan 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 For internal use only. May be renamed or removed in a future release.
See Also:
  • Field Details

  • Constructor Details

    • BaseUIUnitTest

      public BaseUIUnitTest()
  • Method Details

    • discoverRoutes

      protected com.vaadin.testbench.unit.internal.Routes discoverRoutes()
    • discoverRoutes

      protected static com.vaadin.testbench.unit.internal.Routes discoverRoutes(Set<String> packageNames)
      Discover and return Routes for mocked Vaadin core system.
      Returns:
      Routes
      See Also:
      • initVadinEnvironment()
    • 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.
    • 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

      protected Set<Class<?>> 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 as InstantiatorFactory, ResourceProvider, etc.
      Returns:
      set of services implementation classes, never null.
    • fireShortcut

      public void fireShortcut(Key key, KeyModifier... modifiers)
      Simulates a keyboard shortcut performed on the browser.
      Parameters:
      key - Primary key of the shortcut. This must not be a KeyModifier.
      modifiers - Key modifiers. Can be empty.
    • getCurrentView

      public HasElement getCurrentView()
      Get the current view instance that is shown on the ui.
      Returns:
      current view
    • test

      public <T extends ComponentTester<Y>, Y extends Component> T test(Y component)
      Wrap component with ComponentTester best matching component type.
      Type Parameters:
      T - tester type
      Y - component type
      Parameters:
      component - component to get test wrapper for
      Returns:
      component in wrapper with test helpers
    • test

      public <T extends ComponentTester<Y>, Y extends Component> T test(Class<T> tester, Y component)
      Wrap component in given ComponentTester.
      Type Parameters:
      T - tester type
      Y - component type
      Parameters:
      tester - test wrapper to use
      component - component to wrap
      Returns:
      initialized test wrapper for component
    • $

      public <T extends Component> ComponentQuery<T> $(Class<T> componentType)
      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
    • $

      public <T extends Component> ComponentQuery<T> $(Class<T> componentType, Component fromThis)
      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 for
      fromThis - component used as starting element for search.
      Returns:
      a query object for finding components
    • $view

      public <T extends Component> ComponentQuery<T> $view(Class<T> componentType)
      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.
    • testingEngine

      protected abstract String 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.