The end-to-end test profile

Even though it has the word test in its name, the end-to-end test, or, E2E test for short, is quite different from unit tests. The E2E test has nothing to do with those unit tests code or the @ActiveProfiles annotation. You can think of those E2E tests as mini robots. They can open browsers with the help of tools like Nightwatch, and test the application's features directly from the browser as an actual application user. 

In Chapter 8Creating the Application Scaffold - Taking off Like a Rocketwe combined the build steps of the frontend into Maven's build process. In this process, before the E2E test starts, we start the application by running mvn spring-boot:start, and then we execute the E2E test cases. Once that is done, we stop the application. Because we have set the environment variable, spring_profiles_active, to be dev. (see Chapter 8, Creating the Application Scaffold - Taking off Like a Rocket), when we run the E2E tests with the mvn clean install command, we're actually using the dev profile. That's why you see those autogenerated users showing up in the user table in the database.

This build process that has the E2E test combined into Maven's build lifecycle seems to be working well. However, it will become an issue when we build the application with Jenkins. We will talk about Jenkins in the next chapter. On the Jenkins server, the environment is not the dev environment. Thus, we cannot use the "dev" profile when we build with Jenkins. We need an isolated and refreshed environment to perform the E2E test before the code is deployed to the production. It is better that we give this environment a profile, such as "e2e"

Let's add src/main/resources/application-e2e.properties, and set the active profile to be "e2e" in spring-boot-maven-plugin, as in the following:

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>pre integration test</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<profiles>
<profile>e2e</profile>
</profiles>
</configuration>
</execution>
...
</executions>
</plugin>

The <profile> we added to spring-boot-maven-plugin is to set the active Spring Profile. It is not the profile that Maven supports. We will talk about Maven's profile in the next chapter.

Here is how src/main/resources/application-e2e.properties looks:

spring.datasource.url=jdbc:mysql://localhost:3306/task_agile_e2e?useSSL=false
spring.datasource.username=root
spring.datasource.password=1234

spring.jpa.hibernate.ddl-auto=create-drop

As you can see, we use a different database, task_agile_e2e, for the E2E test, and we ask the JPA to autogenerate the tables and drop them after the testing. All the other settings will come from the base configuration, application.properties.

In the User.java entity, we set the length of the password field to be 30 characters, which is not enough to store the encrypted version of the password. We need to fix it by changing it to 128 characters. See the Fixes at the end section for more details.

In the next chapter, we will do a refactoring to our build process to make it fit the continuous delivery's life cycle.

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

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