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
- See here a Reference Implementation (Author - Neeraj Sidhaye @BeTheCodeWithYou)
- What all stuffs the above project covers or why it is useful for developers as well as testers?
- This project shows Fail-Fast approach and how easily you can do integration testing
- How you should or you can set up your build pipe line to achieve zero defect APIs
- Lists how envvironment switching to CI/DIT/SIT/UAT(ci2/dit2/sit2) is so easy and effortless
- Covers how the smart test reports can be useful to trace test failures
- How the entire test suite can be reused as a regression pack for testers(the below article explains that)
- How the Developers and Test-Engineers can collaborate for the best quality APIs
- This article @Medium exaplains step by step approach for achieving zero defect APIs (same author)
<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>
- The JUnit integration tests are located under-
- test/java/integrationtests/get
- test/java/integrationtests/put
You can run and debug them individually.
The suite JUnit suite test located-
src/test/java/integrationtests/IntegrationTestSuite.java
The JUnit unit tests are located as usual in their respective package, under root of-
src/test/java/com/springboot
i.e. under packagecom.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
- The unit tests run as usual in the
test
phase - Then the integration-tests are fired in the
<goal>integration-test</goal>
as configured in thepom.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>
- Please look at the the Suite-Test class
<include>integrationtests.IntegrationTestSuite.java</include>
which is pointing to the root of the tests in the test-resources folderresource/integration_tests
i.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.
}
}