覆盖TestPropertySource值

时间:2019-05-16 13:16:11

标签: java spring

有没有办法在Spring中以编程方式更改TestPropertySource?

我尝试直接覆盖配置属性(在下面的代码中),该属性不起作用。是否想根据环境变量覆盖TestPropertySource吗?例如,当它在本地运行时,我希望它选择一个属性文件,当在其他地方运行时,我希望它选择另一个属性文件。

这是我的不及格测试:

@TestPropertySource(locations = "classpath:config/application_e2e.properties")
@SpringBootTest
public class CreateCaseTest {

    private MyService myService = new MyService();
    private final static String env = System.getenv("ENV");

    static {
        if (env != null && env.equals("LOCAL")) {
            System.setProperty("pdf.url", "http://localhost:5300");
        }
    }

@Test
    public void myTest() {
        String test = "testing";

        Long id = myService.submit(test);
        assertEquals("123", id);

    }
}


0 个答案:

没有答案