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

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

我想为我的使用特定JVM参数的spring boot应用程序创建一个测试,我希望JVM参数仅与该测试一起使用。

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

java spring spring-boot testing jvm
2个回答
0
投票

如果使用的是IntelliJ Idea,则可以从运行/调试配置-> VM选项中传递参数以进行测试。如果您使用的是Maven,则可以在surefire-plugin配置中传递参数:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <argLine>-Xmx1G</argLine>
            </configuration>
        </plugin>

并且请记住,Maven选项将覆盖Idea的默认值(如果已设置)。


0
投票

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

static {
    System.setProperty("http.proxyHost", "myproxyserver.com");
    System.setProperty("http.proxyPort", "80");
    System.setProperty("https.proxyHost", "myproxyserver.com");
    System.setProperty("https.proxyPort", "80");
}
© www.soinside.com 2019 - 2024. All rights reserved.