Search⌘ K
AI Features

Running Cypress Tests from JUnit

Explore the process of running Cypress end-to-end tests automatically from JUnit using Testcontainers. Understand how to configure Docker containers for Cypress and PostgreSQL, manage dynamic ports, and integrate test reporting for seamless testing within a Spring Boot application.

To work with Cypress tests, we need to find a way to run them automatically when we build our project. The easiest way is to run them from JUnit with our other automated tests.

Testcontainers

To avoid installing Cypress for running the tests, we’ll use Testcontainers with a Docker image that contains Cypress.

Let’s start by adding two dependencies to the pom.xml:

XML
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.wimdeblauwe</groupId>
<artifactId>testcontainers-cypress</artifactId>
<version>${testcontainers-cypress.version}</version>
<scope>test</scope>
</dependency>

The org.testcontainers:junit-jupiter dependency allows us to use Testcontainers from JUnit 5. The ...