简体   繁体   English

使用intellij运行时,单元测试中的系统属性

[英]System properties in unit tests when run with intellij

I m running a unit test using the intellij runner. 我正在使用intellij跑步程序进行单元测试。

In the main method of the app, we set the keystore to the value: 在应用程序的主要方法中,我们将密钥库设置为以下值:

/home/oozen/workspace/wakeup/src/main/resources/Certif.p12

public void run(String... args){
        System.setProperty("javax.net.ssl.keyStore", vodafoneKeystore);
        System.setProperty("javax.net.ssl.keyStorePassword", vodafoneKeystorePassword);
        logger.info(" **************** WakeUpApp **************** ");
        logger.info("vodafoneKeystore is set to {}", vodafoneKeystore);
    }

This works ok on production. 这样可以正常生产。 But not on unit tests when I run with intellij. 但是当我使用intellij时,没有进行单元测试。

In the tests, when i log the result of getProperty, i see what we set in the code. 在测试中,当我记录getProperty的结果时,我看到了我们在代码中设置的内容。

In the beginning of my test method, i can see the value is correctly set: 在测试方法的开始,我可以看到该值已正确设置:

    logger.info(" ################## KEYSTORE : {}", System.getProperty("javax.net.ssl.keyStore"));

 ################## KEYSTORE : /home/oozen/workspace/wakeup/src/main/resources/Certif.p12

But during the handshake, i see the message: no certificate found resulting in failure in the authentication. 但是在握手期间,我看到消息: no certificate found导致身份验证失败。

Any ideas as to why? 有什么想法吗?

I know that I can run the test with an arg : ... -Djavax.net.ssl.keyStore=... But i donT want to.. :) 我知道我可以使用arg来运行测试:... -Djavax.net.ssl.keyStore=...但我不想.... :)

Also, @Thiru shows a way to set it externally, but my aim is to be able to set it from the code and to be able to rely on it in the unit tests. 另外,@ Thiru显示了一种在外部进行设置的方法,但我的目标是能够从代码中进行设置,并能够在单元测试中依赖它。

Thanks in advance 提前致谢

You can accomplish using Path Variables in Preferences. 您可以在首选项中使用路径变量。

Follow the steps below: 请按照以下步骤操作:

  • Open Preference -> Path Variables 打开首选项->路径变量
  • Click the + icon 点击+图标
  • Add the property name and value 添加属性名称和值
  • Click apply 点击申请

Please refer to the below image 请参考下图

图片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM