Search⌘ K
AI Features

First Cypress Test

Explore how to set up and run your first Cypress test for a Spring Boot and Thymeleaf application by creating test APIs, resetting the database, and automating user login checks to ensure front-end functionality.

Pre-requisites

A good unit or integration test needs to start from a well-known situation.

For a smooth testing process, we can expose certain REST API endpoints that will put the database in a well-known state. This could be empty, with a few test users, or with many users to test pagination, etc.

Let’s start by adding IntegrationTestController to src/main/java/test:

  • Create a @RestController to call the endpoints from the Cypress tests.

  • All endpoints will be served at /api/integration-test.

  • These endpoints should only be started when running as a test. This mustn’t be exposed when running on production as it wipes the complete database.

  • Inject the UserService in order to create the default users.

  • Add an endpoint /reset-db so ...