com.vaadin.testbench.unit.

Class 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();
     }
 }
 
 

  • Constructor Details

    • SpringUIUnit4Test

      public SpringUIUnit4Test()
  • Method Details

    • lookupServices

      protected Set<Class<?>> lookupServices()

      Description copied from class: BaseUIUnitTest

      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.

      Overrides:

      lookupServices in class BaseUIUnitTest

      Returns:

      set of services implementation classes, never null.

    • initVaadinEnvironment

      public void initVaadinEnvironment()

      Description copied from class: BaseUIUnitTest

      Create mocked Vaadin core obects, such as session, servlet populated with Routes, UI etc. for testing and find testers for the components.

      Overrides:

      initVaadinEnvironment in class UIUnit4Test