Spring Framework
Video

REST API to read entities

Lesson 3


Further resources


You can find the source code for this CRUD application on GitHub: https://github.com/rieckpil/blog-tutorials/tree/master/demo-crud-application


For more testing deep-dive with Spring Boot using a real world application example (Java 14, Spring Boot, React, TypeScript, AWS, Keycloak, PostgreSQL), take a look at the Testing Spring Boot Applications Masterclass.

  • Daniel Polách says:

    Hmmm, I would say, that we can do more in getBookWithUnknownShouldReturn404, because if you don’t have getBookById method in controller and you run the test, it doesn’t fail. But is it correct? It doesn’t fail because you don’t have the particular endpoint, so it must but 404, but not because book with given ID was not found. So I would also add something like .andExpect(status().reason(“Book with ID ’42’ was not found.”)), so it fails if particular endpoint is missing.

    • Daniel Polách says:

      And if I’m right, can we call it “false positive”? 🙂

    • rieckpil says:

      Hi Daniel,

      good point – that’s true. The current test can lead to a false positive in case the endpoint is entirely missing. Adding the additional expecting as you propose can help here. Otherwise, as we have the happy-path for the same URL inside this test class, we have an additional verification that this endpoint exists.

      Kind regards,
      Philip

  • Pen
    >