Class SpringUIUnit4Test

java.lang.Object
com.vaadin.testbench.unit.UIUnit4Test
com.vaadin.testbench.unit.SpringUIUnit4Test
All Implemented Interfaces:
TesterWrappers

@TestExecutionListeners(listeners=UITestSpringLookupInitializer.class, mergeMode=MERGE_WITH_DEFAULTS) public abstract class SpringUIUnit4Test extends UIUnit4Test
Base JUnit 4 class for UI unit testing applications based on Spring Framework. This class provides functionality of the Spring TestContext Framework, in addition to set up a mock Vaadin Spring environment, so that views and components built upon dependency injection and AOP can be correctly be handled during unit testing. Usually when unit testing a UI view it is not needed to bootstrap the whole application. Subclasses can therefore be annotated with @ContextConfiguration or other Spring Testing annotations to load only required component or to provide mock services implementations.
 
 @ContextConfiguration(classes = ViewTestConfig.class)
 public class ViewTest extends SpringUIUnit4Test {

 }
 @Configuration
 class ViewTestConfig {
     @Bean
     MyService myService() {
         return new my MockMyService();
     }
 }
 
 
  • Field Details

  • Constructor Details

    • SpringUIUnit4Test

      public SpringUIUnit4Test()
  • Method Details

    • 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.
    • initVaadinEnvironment

      public void initVaadinEnvironment()
      Overrides:
      initVaadinEnvironment in class UIUnit4Test
    • cleanVaadinEnvironment

      protected void cleanVaadinEnvironment()
    • 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.