JUnit получить системные свойства в IntelliJ, но не в Eclipse - PullRequest
0 голосов
/ 30 апреля 2018

Я пытаюсь использовать systemPropertyVariable, определенный в pom над maven-surefire-plugin, когда я запускаю тестовый пример из JUnit.

Это соответствующий файл peace of pom.xml:

  <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.16</version>
      <configuration>
        <systemPropertyVariables>
          <my.value>NOTNULL</my.value>
          <buildDirectory>${project.build.directory}</buildDirectory>
        </systemPropertyVariables>
      </configuration>
  </plugin>

Это метод теста:

public void testApp(){
    System.out.println(System.getProperty("my.value"));
    System.out.println(System.getProperty("buildDirectory"));
    System.out.println(this.getClass().getClassLoader().getResourceAsStream("environment.properties"));
    ClassLoader classloader = Thread.currentThread()
            .getContextClassLoader();
    System.out.println(classloader.getResource("environment" + File.separator + System.getProperty("env")
            + File.separator + "environment.properties"));
}

Если я запускаю тестовый пример из Eclipse, переменные недоступны:

null
null
null
null

Но если я запущу контрольный пример из IntelliJ, переменные будут доступны:

NOTNULL
/Users/jaimebarrio/git/test-properties/target
null
null

Process finished with exit code 0

Может кто-нибудь объяснить, почему это происходит?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...