The test profile
For any tests, it is ideal to keep the configuration for them in an isolated environment. The "test" profile is for this purpose. As you have already seen, we use @ActiveProfiles("test") in the unit test code. Instead of looking for src/main/resources/application-test.properties, Spring will look for src/test/resources/application.properties, in which the biggest difference is the datasource configuration. In test "test" profile, we use H2 to speed up the performance. In other environments, we use MySQL.We want to keep H2 only for the tests, and that is why we add the H2 dependency in pom.xml with the test scope.
One interesting thing about the "test" profile is that if you set the active profile to be "test" by using methods ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access