Running E2E tests before pushing the code to VCS

We've been doing this since Chapter 9, Forms and Validation - Starting with the Register Page, with the mvn clean install command. Currently, we have only created two E2E test suites, one for the register page and the other for the login page. Both of them are lightweight. That's why our build completes fast. However, in the future, once we create enough tests to cover all the features of the application, it could take more than fifteen minutes or half an hour to finish all the tests. The situation could be worse for large-scale applications. Even for a tiny change, such as a typo, we would have to sit there and wait for all E2E tests to finish before committing the code.

It is better that we make the step of executing the E2E tests optional in the Maven build process. That is, by default, with the mvn clean install command, E2E tests won't be executed. When you want to execute the E2E tests, you can opt-in using a flag. Maven's profile feature is perfect for these kinds of requirements. As you can see in the following diagram, we will extract the steps with a flag into a Maven profile, called local-e2e. We name it local-e2e to make it clear that executing the E2E tests using the Maven command is only used in the local development environment. As you will see in the next section, with Jenkins, we will not use Maven to trigger the E2E tests. The Maven build process is shown here, with optional steps included:

Figure 15.3: The Maven build process with optional steps

Here is the change to pom.xml. We extract the spring-boot:start, integration-test, and spring-boot:stop steps into the local-e2e profile as follows:

<profiles>
<profile>
<id>local-e2e</id>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
...
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${codehaus.version}</version>
<executions>
...
</executions>
...
</plugin>
</plugins>
</build>
</profile>
</profiles>

With this change, when we execute the mvn clean install command, no E2E test will be executed. We can add the -P argument, followed by the Maven profile's ID, to include the E2E tests, such as the following:

mvn clean install -P local-e2e

To avoid confusion, we rename the test:integration npm script to test:local-e2e. We also add another script, test:staging-e2e, for executing E2E tests in the staging environment. You can check the commit record shown at the end of this section for details.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.237.164