如何创建使用特定JVM参数运行的Spring Boot测试 [英] How to create a Spring Boot test that runs with specific JVM arguments
本文介绍了如何创建使用特定JVM参数运行的Spring Boot测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为使用特定JVM参数的spring boot应用程序创建一个测试,我希望JVM参数仅与该测试一起使用.
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.
推荐答案
我通过在类中添加静态块并设置系统属性来解决此问题:
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");
}
这篇关于如何创建使用特定JVM参数运行的Spring Boot测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文