0
0
Spring Bootframework~5 mins

Test profiles and configuration in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A@TestProfile
B@ActiveProfiles
C@ProfileTest
D@EnableProfiles
Where do you typically define profile-specific properties in Spring Boot?
Aapplication-{profile}.properties or application-{profile}.yml
Btest.properties only
Capplication.properties only
Dpom.xml
What happens if you do not specify a profile when running Spring Boot tests?
ASpring Boot randomly picks a profile
BTests will fail to run
CSpring Boot uses the production profile
DSpring Boot uses the default profile
How can you activate a test profile from the command line?
AUsing --test.profile=active
BUsing --profile=test
CUsing --spring.profiles.active=test
DUsing --activate.test.profile
Why might you use an in-memory database in a test profile?
ATo isolate tests and speed up execution
BTo connect to production data
CTo increase test complexity
DTo disable database access
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.