如何创建使用特定 JVM 参数运行的 Spring Boot 测试

ous*_*ema 0 java testing spring jvm spring-boot

我想为使用特定 JVM 参数的 Spring Boot 应用程序创建一个测试,我希望 JVM 参数仅用于此测试。

这可能吗 ?我的目标是为一个测试设置一个代理,所以如果有另一种方法来实现这一点,请提出建议。

ous*_*ema 9

我通过在类中添加一个静态块并设置系统属性来解决这个问题:

static {
    System.setProperty("http.proxyHost", "myproxyserver.com");
    System.setProperty("http.proxyPort", "80");
    System.setProperty("https.proxyHost", "myproxyserver.com");
    System.setProperty("https.proxyPort", "80");
}
Run Code Online (Sandbox Code Playgroud)