title: why does test class not set ActiveProfiles using spring boot 2.5.5?
body: <p>In spring boot 2.5.5 application, in a test class, I am trying to read a property from the environment. When I try to debug and the controller goes to TradeController...environment.getProperty(&quot;spring.profiles.active&quot;); returns null.</p>
  <p>Below is the class I want to test</p>
  <pre><code>@RestController
  public class TradeController{
  
    @Autowired
    private TradeServiceImpl tradeServiceImpl; 
   
    @Autowired
    private Environment environment;
  
    @GetMapping(&quot;/getTrade&quot;)
    public ResponseEntity&lt;String&gt; getTrade(@PathVariable final String 
      tradeId){
        if(StringUtils.isNotBlank(tradeId){
           String profile = environment.getProperty(&quot;spring.profiles.active&quot;);
         }
  
         List&lt;Trade&gt; trades = tradeServiceImpl.getAllTrades(tradeId);
     }
  
  }
  </code></pre>
  <p>and below is the test class.</p>
  <p>Will @ActiveProfiles(&quot;test) in below test, set spring.profiles.active=test  ?</p>
  <p>When I run the test , environment.getProperty(&quot;spring.profiles.active&quot;); in TradeController returns null. However, the enviorment variable in TradeController looks as below
  enviornment={StandardEnvironment@746}&quot;StandardEnvironment{activeProfiles=[test],....}</p>
  <p>It works fine when I run the test on spring boot 2.2.8-RELEASE, environment.getProperty(&quot;spring.profiles.active&quot;); in TradeController  returns test. I am confused, why does it work with spring boot 2.2.8 and not with 2.5.5.?</p>
  <p>Am I missing anything?</p>
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @WebMvcTest(value = TradeController.class)
  @ActiveProfiles(&quot;test)
  class TradeControllerTest{
     @Autowired
     private MockMvc mockMvc;
     
  
      @MockBean
      private TradeServiceImpl tradeServiceImpl;
  
      @Mock
      private ConfigurableEnvironment enviroment;
  
      @Before
      public void setup(){
        MockitoAnnotations.initMocks(this);
      }
  
     @Test
      public void test() throws Exception{
        Mockito.doNothing().when(tradeServiceImpl).getAllTrades(any());
        RequestBuilder requestBuilder = MockMvcRequestBuilder.get(new 
            URI(&quot;/getTrades&quot;)).accept(MediaType.APPLICATION_JSON);
        MvcResult  result = mockMvc.perform(requestBuilder).andReturn();
        assertEquals(result.getResponse().getStatus(), 400);
      }
  
  } 
  </code></pre>
  <p>My pom looks below spring dependencies .. spring boot is 2.5.5</p>
  <pre><code>&lt;dependency&gt;
     &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
     &lt;artifactId&gt;spring-boot-starter-web&gt;&lt;/artifactId&gt;
  &lt;dependency&gt;
  &lt;dependency&gt;
     &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
     &lt;artifactId&gt;spring-boot-starter-actuator&gt;&lt;/artifactId&gt;
  &lt;dependency&gt;
  &lt;dependency&gt;
     &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
     &lt;artifactId&gt;spring-boot-starter-jdbc&gt;&lt;/artifactId&gt;
  &lt;dependency&gt;
  &lt;dependency&gt;
     &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
     &lt;artifactId&gt;spring-boot-starter-retry&gt;&lt;/artifactId&gt;
  &lt;dependency&gt;
  &lt;dependency&gt;
     &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
     &lt;artifactId&gt;spring-boot-starter-test&gt;&lt;/artifactId&gt;
  &lt;dependency&gt;
  
  &lt;dependency&gt;
     &lt;groupId&gt;org.springframework&lt;/groupId&gt;
     &lt;artifactId&gt;spring-web&gt;&lt;/artifactId&gt;
     &lt;version&gt;5.3.11&lt;/version&gt;
  &lt;dependency&gt;
  </code></pre>