0

I followed How to set env variables for maven to run test correctly? and configured my pom like this :

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-surefire-plugin</artifactId>
   <version>2.15</version>
   <configuration>
       <systemPropertyVariables>
           <SENDGRID_USERNAME>username</SENDGRID_USERNAME>
           <SENDGRID_PASSWORD>password</SENDGRID_PASSWORD>
       </systemPropertyVariables>
   </configuration>
</plugin>

when i run mvn test command, it is giving the following error,

Error in custom provider, java.lang.IllegalStateException: SENDGRID_PASSWORD env variable must be set.

What am i doing wrong ?

When I was doing research to find the answer, I found out the following : ProcessBuilder can be used set env for processes spawned with it. I dont know whether ProcessBuilder helps in my case as I am not spawning any processes. My project is maven project and i run test with mvn test command.

Can any body explains me how to set env for situations like this (i.e., maven + junit )

I am able to set the properties but the problem is how to set environment variable as my program is expecting the env variable.

Community
  • 1
  • 1
vikas
  • 1,318
  • 4
  • 16
  • 33
  • That looks fine to me. How is the env variable being retrieved, System.getProperty("SENDGRID_PASSWORD") ? Have u checked that? – vikingsteve Jul 11 '13 at 06:56
  • When i tried to retrieve in @BeforeClass method, System.getProperty("SENDGRID_PASSWORD") returned `null` – vikas Jul 11 '13 at 07:07
  • Well that's weird, since system properties should be available already when you reach a @BeforeClass method. – vikingsteve Jul 11 '13 at 08:01
  • @vikingsteve you are right, I can verify env in @BeforeClass. The issue I am facing is; in my MyClassTest.java i am trying to instantiate MyClass. And one of the member of MyClass is initialized with Guice injection. This is where the exception is being throws as: `tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.778 sec <<< FAILURE! - in com.a.b.c.MyClassTest testMethod() Time elapsed: 0.778 sec <<< ERROR! com.google.inject.ProvisionException: Guice provision errors: 1) Error in custom provider, java.lang.IllegalStateException: SENDGRID_PASSWORD env variable must be set`. – vikas Jul 11 '13 at 08:12
  • No worries, thanks for that info, it's outside my knowledge so I edited your question and added the `guice` tag. – vikingsteve Jul 11 '13 at 08:38

1 Answers1

2

If I read the documentation correctly, the configuration to use is:

 <environmentVariables>
       <SENDGRID_USERNAME>username</SENDGRID_USERNAME>
       <SENDGRID_PASSWORD>password</SENDGRID_PASSWORD>
 </environmentVariables>

Could this be the issue?

Source: http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#environmentVariables

GeertPt
  • 16,398
  • 2
  • 37
  • 61
Aurélien Thieriot
  • 5,853
  • 2
  • 24
  • 25