10

I've managed to get the test task to run my unit tests, but they fail because env properties I am using are not set, eg: String base=System.getenv("TESTNG_BASE_PATH");

So, I've done something like:

tasks.withType(Test) {
   systemProperty 'TESTNG_BASE_PATH','long\\path\\to\env\var\value'   
}

But I still get the same exception from my code that the file is not found, so its obviously not the right way of doing this.

So how to do this, please?

1 Answer 1

8

If you are getting via System.getenv(...) you'll need to set an environment variable. I've also included a command line flag for switching on/off standard streams

tasks.withType(Test) { 
    environment 'TESTNG_BASE_PATH','long\\path\\to\env\var\value'
    testLogging.showStandardStreams = Boolean.parseBoolean(findProperty('showStandardStreams'))
}

To run you could do

./gradlew check -PshowStandardStreams=true
Sign up to request clarification or add additional context in comments.

5 Comments

I just tried that - still having the same exception thrown by my code :( So I think its not working, but what is compounding the diagnostics difficulty, is that something is intercepting my System.out.println(e.getMessage()); and printStackTrace - because I simply dont see these outputted, only the console output is what test failed, what exception and in which line... thats it.
You can add test { testLogging.showStandardStreams = true } to show System.out and System.err in the console. See here
Excellent! This has finally enabled me to figure out what the problem was. Could you please tell me if we could move the showStandardStreams setting to a command line argument to gradle, so that we can easily use it for debugging when there is a build issue from Jenkins, without committing file changes just to test.
See my updated answer. More info here
Thanks, that problem is solved, but I still have other errors saying something about ENV environment value not being set (a different one) - the best way for me to go forth is to debug while running from Gradle test task - is that possible? How?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.