问题
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