How to create a Spring Boot test that runs with specific JVM arguments

為{幸葍}努か 提交于 2020-08-10 19:09:33

问题


I want a to create a test for my spring boot application that uses specific JVM arguments, I want the JVM arguments to be used with only this test.

Is this possible ? My goal is to set up a proxy for just one test, so if there is another approach to achieve that, please suggest it.


回答1:


I solved this by adding a static bloc in the class and setting the system properties:

static {
    System.setProperty("http.proxyHost", "myproxyserver.com");
    System.setProperty("http.proxyPort", "80");
    System.setProperty("https.proxyHost", "myproxyserver.com");
    System.setProperty("https.proxyPort", "80");
}



回答2:


If you're using IntelliJ Idea, you can pass arguments to test from Run/Debug configuration -> VM options. If you're using Maven, you can pass arguments in surefire-plugin configuration:

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

And remember, that Maven options overrides Idea defaults (if set).



来源:https://stackoverflow.com/questions/60637867/how-to-create-a-spring-boot-test-that-runs-with-specific-jvm-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!