Loading repository data…
Loading repository data…
authorjapps / repository
Zerocode based integration-tests for a spring-boot application
This demo project exaplins how JUnit and Zerocode test framework based integration-tests for a spring-boot application can make everyone's life easy everyday.
Keep it simple and easy while doing the integration tests
<dependency>
<groupId>org.jsmart</groupId>
<artifactId>zerocode-rest-bdd</artifactId>
<version>1.2.x</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
You can run and debug them individually.
The suite JUnit suite test located-
src/test/java/integrationtests/IntegrationTestSuite.javaThe JUnit unit tests are located as usual in their respective package, under root of-
src/test/java/com/springboot i.e. under package com.springboot@TargetEnv("application_host.properties")
@RunWith(ZerocodeSpringBootRunner.class)
public class VerifyGetFeature {
@Test
@JsonTestCase("integration_tests/get/get_new_customer_by_id_test.json")
public void test_getNewCustomerDetailsById() throws Exception {
}
}
where the ZerocodeSpringBootRunner starts the spring application, then fires the tests.
public class ZerocodeSpringBootRunner extends ZeroCodeUnitRunner {
public ZerocodeSpringBootRunner(Class<?> klass) throws InitializationError {
super(klass);
Application.start(); //<--- Starts the Spring application and checks all bean wirings have gone well.
}
}
e.g.
mvn clean install
test phase<goal>integration-test</goal> as configured in the pom.xml <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<includes>
<include>integrationtests.IntegrationTestSuite.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<include>integrationtests.IntegrationTestSuite.java</include> which is pointing
to the root of the tests in the test-resources folder resource/integration_testsi.e. as below-
@TargetEnv("abc_bankapp_host.properties")
@TestPackageRoot("integration_tests") //You can point this to any package you need
@RunWith(ZerocodeSpringBootSuite.class)
public class IntegrationTestSuite {
}
@RunWith(ZerocodeSpringBootSuite.class)
Ans: It starts the spring applications and then fires the tests once by one. See below how it brings up the application.
public class ZerocodeSpringBootSuite extends ZeroCodePackageRunner {
static{
Application.start();
}
public ZerocodeSpringBootSuite(Class<?> klass) throws InitializationError {
super(klass);
Application.start(); //<--- Starts the Spring application and checks all bean wirings have gone well.
}
}