Hi,
I’m trying to add some specific test for certain more complex components. These components extend VerticalLayout, and have some interaction between different sub-components.
I thought I would use UI Unit Testing for this.
The thing here is that the entry point is to navigate to a Route and then to interact with components on the page.
Since I want to test this component in isolation I decided to create a new Route, with just that component in the test module of the application.
@Route("test-my-component")
class MyComponentTestView extends VerticalLayout {
public MyComponentTestView(SomeService someService) {
add(new MyComponent(someService));
}
}
And then my test would look like this:
@SpringBootTest(classes = MyTestConfiguration.class)
@ComponentScan(basePackages = "...")
class MyComponentTest extends SpringUIUnitTest {
@MockBean
private SomeService someService;
@Test
public void testMyComponent() {
// mocking the service
when(someService.loadData()).thenReturn(List.of(...));
final MyComponentTestView navigate = navigate(MyComponentTestView.class);
...
}
}
When I run this, I see output from Vaadin listing all the discovered views, but my TestView, which is in the test-module (not main) is not being discovered. Is there a way to include this TestView? And preferably even exclude the Views not under test?
Or is my whole idea to do these kinds of tests not how it was intended?
Thank you!
Kristof