UIUnitTests fails with XYZ has a public no-arg constructor

I want to start with UIUnitTests for my Spring Boot Vaadin 24.1.x application. Usually my view classes are annotated with @lombok.RequiredArgsConstructors and then contains plenty of fields private final ServiceXYZ serviceXyz in order to enable constructor injection for all my dependencies. If I try to navigate to such a view in my UIUnitTest with navigate(XYZView.class, params); then the test failed with the error mentioned below. The test is annotated with @SpringBootTestbut it seems that the Vaadin Test framework is trying to create the view class by the default constructor instead of using the instance already created by Spring.

`java.lang.IllegalArgumentException: Unable to create an instance of ‘XYZView’. Make sure the class has a public no-arg constructor.
at com.vaadin.flow.internal.ReflectTools.createProxyInstance(ReflectTools.java:520)
at com.vaadin.flow.internal.ReflectTools.createInstance(ReflectTools.java:452)
at com.vaadin.flow.di.DefaultInstantiator.create(DefaultInstantiator.java:134)
at com.vaadin.flow.di.DefaultInstantiator.getOrCreate(DefaultInstantiator.java:63)
at com.vaadin.testbench.unit.mocks.MockInstantiator.getOrCreate(MockInstantiator.kt:31)
at com.vaadin.flow.di.Instantiator.createRouteTarget(Instantiator.java:136)
at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.lambda$getRouteTarget$1(AbstractNavigationStateRenderer.java:131)
at java.base/java.util.Optional.orElseGet(Optional.java:364)
at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.getRouteTarget(AbstractNavigationStateRenderer.java:130)
at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.sendBeforeEnterEventAndPopulateChain(AbstractNavigationStateRenderer.java:479

at com.vaadin.testbench.unit.BaseUIUnitTest.navigate(BaseUIUnitTest.java:259)
at com.vaadin.testbench.unit.UIUnitTest.navigate(UIUnitTest.java:73)

`
message.txt (5.26 KB)

Just to be sure, is your test class extending from SpringUIUnitTest?

No, from com.vaadin.testbench.unit.UIUnitTest as mentioned in the docs

ah … I see it in the docs … SpringUIUnitTest

ok, worked :+1:t2:

Maybe the docs should be clearer at this point:

Testing with UIUnitTest provides specialized base test classes that integrate with the Spring Testing Framework: SpringUIUnitTest for JUnit 5, and SpringUIUnit4Test for JUnit 4.

did not trigger me to change the class hierarchy