Orkun Ozen :
We have a test class which I'd like to run only on Jenkins.
I think this can be achieved by checking the active spring profile (such as jenkins
) or when the local machine name is XYZ
.
The issue is, the loading of the application context fails when we try to run this on machines other than jenkins.
So I cannot check the profile or a parameter in the @Before method of the test class per se.
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Config.class)
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@ActiveProfiles("clusterMongo")
public class MongoTest {
@Before
public void setupClass() {
// Ignore test if not running on white listed machines
org.junit.Assume.assumeTrue(AuthTools.isJenkins()); // wonT work !!
}
...
Any ideas how we can achieve this?
Can i maybe use Conditional beans?
aka-one :
Instead of doing it programmatic, you have a declarative option.
You can configure the surefire plugin to skip certain tests for a certain Maven profile:
<profile>
<id>skip-test</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/MongoTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
On non-Jenkins run: mvn test -Pskip-test