0
0
Spring Bootframework~10 mins

Test profiles and configuration in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the active Spring profile in application.properties.

Spring Boot
spring.profiles.active=[1]
Drag options to blanks, or click blank then click option'
Adev
Bprod
Cdefault
Dtest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prod' or 'dev' instead of 'test' when running tests.
2fill in blank
medium

Complete the annotation to activate the 'test' profile for a Spring Boot test class.

Spring Boot
@ActiveProfiles([1])
public class MyServiceTest {}
Drag options to blanks, or click blank then click option'
A"dev"
B"test"
C"prod"
D"default"
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes around the profile name.
Using the wrong profile name.
3fill in blank
hard

Fix the error in the YAML configuration to define a 'test' profile property.

Spring Boot
spring:
  profiles: [1]
  datasource:
    url: jdbc:h2:mem:testdb
Drag options to blanks, or click blank then click option'
Atest
Binclude: test
Cdefault: test
Dactive: test
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'active: test' under profiles instead of 'test'.
Misplacing colons or indentation.
4fill in blank
hard

Fill both blanks to correctly inject a property value from the 'test' profile in a Spring component.

Spring Boot
@Value("$[1]")
private String [2];
Drag options to blanks, or click blank then click option'
Aapp.test.value
Bapp.prod.value
CtestValue
DprodValue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a production property key when testing.
Variable name not matching the property meaning.
5fill in blank
hard

Fill all three blanks to create a test configuration class that activates the 'test' profile and defines a bean.

Spring Boot
@Configuration
@Profile([1])
public class TestConfig {

  @Bean
  public String sampleBean() {
    return [2];
  }

  public String getProfile() {
    return [3];
  }
}
Drag options to blanks, or click blank then click option'
A"test"
B"This is a test bean"
D"prod"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong profile name in @Profile.
Returning production strings in test beans.