为了进行junit,应使用资源或配置文件

问题描述 投票:0回答:1

在Spring Boot中,我们可以有很多配置文件:local,dev,qa,prod。所以我们需要为它们每个创建一个属性文件。

如果我想在本地运行我的junit测试,是否需要在其中创建另一个属性

src / test / resources或我应该为此使用配置文件

spring-boot junit
1个回答
0
投票

如果需要单独的配置文件,可以将其与其余文件一起放在src / main / resources中。

要激活配置文件,可以使用以下方法激活测试配置文件:

@SpringBootTest
@ActiveProfiles("test")
class SpringBootProfileTest {

  @Value("${foo}")
  String foo;

  @Test
  void test(){
    assertThat(foo).isEqualTo("bar");
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.