com.vaadin.testbench.unit.

Class SpringUIUnitTest

All Implemented Interfaces:

TesterWrappers

@ExtendWith(org.springframework.test.context.junit.jupiter.SpringExtension.class) @TestExecutionListeners(listeners=UITestSpringLookupInitializer.class, mergeMode=MERGE_WITH_DEFAULTS) public abstract class SpringUIUnitTest extends UIUnitTest

Base JUnit 5 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)
 class ViewTest extends SpringUIUnitTest {

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

  • Constructor Details

    • SpringUIUnitTest

      public SpringUIUnitTest()
  • 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

      @BeforeEach protected 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 UIUnitTest