Recall & Review
beginner
What is the purpose of test profiles in Spring Boot?
Test profiles in Spring Boot allow you to define different configurations specifically for testing environments. This helps isolate test settings from production or development settings, making tests more reliable and easier to manage.
Click to reveal answer
beginner
How do you activate a test profile in Spring Boot?
You activate a test profile by setting the
spring.profiles.active property to the desired profile name, either in application.properties, application.yml, or as a command-line argument when running tests.Click to reveal answer
intermediate
What is the role of
@ActiveProfiles annotation in Spring Boot tests?The
@ActiveProfiles annotation tells Spring Boot which profile(s) to use when running a test class. This ensures the test loads the correct configuration for that profile.Click to reveal answer
intermediate
How can you define different database configurations for tests using profiles?
You create separate configuration files like
application-test.properties with test-specific database settings. When the test profile is active, Spring Boot loads these settings, allowing tests to use a test database instead of production.Click to reveal answer
beginner
Why is it important to separate test configuration from production configuration?
Separating test and production configurations prevents tests from accidentally affecting real data or services. It also allows tests to run faster and more predictably by using mock or in-memory resources.
Click to reveal answer
Which annotation is used to specify active profiles in a Spring Boot test?
✗ Incorrect
The @ActiveProfiles annotation is the correct way to specify which profile(s) to activate during a Spring Boot test.
Where do you typically define profile-specific properties in Spring Boot?
✗ Incorrect
Spring Boot loads profile-specific properties from files named application-{profile}.properties or application-{profile}.yml.
What happens if you do not specify a profile when running Spring Boot tests?
✗ Incorrect
If no profile is specified, Spring Boot uses the default profile, which may not be suitable for tests.
How can you activate a test profile from the command line?
✗ Incorrect
You activate a profile by passing --spring.profiles.active=test as a command-line argument.
Why might you use an in-memory database in a test profile?
✗ Incorrect
In-memory databases isolate tests from production data and run faster, making tests more reliable and efficient.
Explain how Spring Boot uses profiles to manage different configurations for testing and production.
Think about how you might switch settings like databases or API endpoints between test and real use.
You got /4 concepts.
Describe the steps to set up a test profile in Spring Boot and how to activate it for running tests.
Consider both configuration files and annotations.
You got /4 concepts.