We have a tests Maven project that executes a bunch of cucumber features against real microservices using springboot test and TestNG.
Rather than run the tests via Maven in Jenkins, which will of course build everything, and download all dependencies etc which takes 6 mins in our case, we would like to simply have a fat/Spring boot JAR pre-created and then run Cucumber from within that on the tests contained within it.
I've tried different maven plugins like: maven-shade-plugin with the assembly descriptor, build-helper-maven-plugin and maven-assembly-plugin but it wasn't able to load the classes even though everything was inside. Then, i found this spring documentation where they explain the issues with the classloader and why they've implemented their own way of packaging the fat jar.
Based on that, i've decided to create another module called runner that will contain a springboot app and will launch the TestNG suite programatically. The problem that i have now is that i have 2 spring contexts and it's just not booting.
What i have now is the app "running" but no tests are ran and this is the output:
[TestNG-PoolService-2] org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [bla.bla.config.CucumberSpringConfiguration]: no resource found for suffixes {-context.xml, Context.groovy}.
I see that app is "started" 2 times and i get that last line repeated a bunch of times but nothing happens.
Am I doing something really stupid here? Is there another way to get this thing done?
Thanks
This how the structure looks like:
project root
|
|----tests-cucumber
|------- pom.xml
|------- src/test/java (spring config, cucumber config, cucumber runner)
|------- src/test/resources (feature files, config files)
|
|----tests-runner
|------- pom.xml
|------- src/main/java (spring boot main that triggers TestNG)
|------- src/main/resources (config files that i had to copy from the other module)
|
|-pom.xml
This is how the runner looks like:
@SpringBootApplication
public class Runner {
public static void main(String[] args) {
SpringApplication.run(Runner.class, args);
}
@EventListener(ApplicationReadyEvent.class)
public void init() {
TestNG tng = new TestNG();
tng.setTestClasses(new Class[]{OurAppTestRunner.class});
tng.setOutputDirectory("./test-output");
tng.run();
}
}
The OurAppTestRunner
@CucumberOptions(
features = "classpath:features",
plugin = {"pretty", "html:../target/cucumber-reports/cucumber.html",
"json:../target/cucumber-reports/cucumber.json"
},
glue = {"classpath:com/bla/bla"}
)
public class OurAppTestRunner extends AbstractTestNGCucumberTests {
@Override
@DataProvider(parallel = true)
public Object[][] scenarios() {
return super.scenarios();
}
}
The CucumberSpringConfig
@SpringBootTest(
classes = {our various classes}
)
@EnableConfigurationProperties({SomeTestsProperties.class})
@TestExecutionListeners(listeners = {DependencyInjectionTestExecutionListener.class})
@CucumberContextConfiguration
public class CucumberSpringConfiguration {
}
Later on, based on an error message i've added
@ContextConfiguration(classes = {our various classes})