How to migrate Spring MVC tests to Vaadin Flow?

Hello! I’m getting started with Vaadin Flow. I use TDD and usually work from the outside in. In a typical Spring MVC app I would start by writing a simple MVC test just to make sure that the endpoint is wired up correctly, like this:

@WebMvcTest(HomeController.class)
@Tag("mvc")
class HomeMvcTest {
    @Autowired
    MockMvc mockMvc;

    @Test
    public void getRequestToIndex() throws Exception {
        mockMvc.perform(get("/"))
                .andExpect(status().is2xxSuccessful());
    }

Based on Vaadin documentation, it seems like the closest thing is UIUnitTest. Is that correct? Something like this:

@ViewPackages(classes = {ClockView.class})
@Tag("mvc")
class ClockMvcTest extends UIUnitTest {

    @Test
    public void getRequestToIndex() throws Exception {
        ClockView view = navigate(ClockView.class);

        assertThat(view).isNotNull();
    }
}

Sadly, I can’t actually try it because this testing framework is a paid feature?

Is there another recommended way to test endpoints. I feel like I’m at the very beginning of the journey here, so it seems a little premature to sign up for the Pro license. I was hoping to kick the tires a bit more to make sure I’m making the right choice.

Side question: How do you submit a website bug report? Some the text here in the forum in dark mode is not readable.

Three options:

2 Likes

@anezthes wanna do some healing magic here?

As a workaround: you can configure “Dracula” as theme in your account settings - there it looks okay.

1 Like

The regular dark mode is fixed as well

1 Like

Check out my new article about Karibu Testing @anezthes

1 Like

Thanks for the heads up! I’ll look into it.

1 Like

Thanks Christian! Yes, that’s actually what I’d prefer. I’m not super interested in testing the UI, just the backend behavior.

Thanks Simon! Karibu Seems like a lot of setup for my goal of simply verifying that an endpoint is accessible, but I’ll probably want to look at something like that once authorization and authentication come into play.

Oh, I see now. Karibu can be used instead of diving into a Pro license.

Ok, this seems to serve for now.

@Tag("ui")
class ClockMvcTest extends KaribuTest {

    @BeforeEach
    public void login() {
        UI.getCurrent().navigate(ClockView.class);
    }

    @Test
    public void getRequestToIndex() throws Exception {
        ClockView view = _get(ClockView.class);

        assertThat(view).isNotNull();
    }
}
1 Like