I have a JUnit test using Assumption
to skip the test if the developer's computer doesn't have the pre-requisite software for running it. Despite being "junit", it's an integration test. Something like this:
int isSoftwarePresent = new ProcessBuilder("check software presence").start().waitFor();
Assume.assumeThat("Software not present", isSoftwarePresent, is(equalTo(0)));
However, at one point I realized the test had stopped running on the automated build on Jenkins, due to that assumption, and eventually a regression was introduced which the test was supposed to stop.
To put in other words, the required software went missing from Jenkins slave environment, which caused the test to be skipped.
The automated test is run by maven with the FailSafe plugin, on a Jenkins Pipeline build plan. How can I detect that my environment is Jenkins so that I can make the assumption condition more strict?
That is, I want the condition to be something like this:
boolean isJenkinsBuild = /* true if this is being run inside a Jenkins build, false otherwise */;
boolean isSoftwarePresent = new ProcessBuilder("check software presence").start().waitFor() == 0;
Assume.assumeTrue("Software not present", isSoftwarePresent || isJenkinsBuild);
Or even,
@Test
void testJenkinsEnvironment() {
...
Assume.assumeTrue(isJenkinsBuild);
Assert.assertTrue(isSoftwarePresent);
}
@Test
void testFeature() {
...
Assume.assumeTrue(isSoftwarePresent);
...
}