Giter Site home page Giter Site logo

authorjapps / spring-boot-integration-test Goto Github PK

View Code? Open in Web Editor NEW
19.0 8.0 20.0 372 KB

Zerocode based integration-tests for a spring-boot application

Home Page: https://zerocode.io

License: MIT License

Java 100.00%
java spring springboot integration testing rest api inmemory json assertion

spring-boot-integration-test's Introduction

Spring-boot application - Integration-testing

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

Spring boot + Spring Data + H2 in-memory DB

  • 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)
Needed maven dependencies
<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>

Integration_tests_organization

Where are the integration tests?

  • The JUnit integration tests are located under-
    • test/java/integrationtests/get
    • test/java/integrationtests/put

You can run and debug them individually.

Where is the Suite to run all the tests?

The suite JUnit suite test located-

  • src/test/java/integrationtests/IntegrationTestSuite.java

Where are the unit tests cases?

The 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

How to run a single scenario e.g. a GET or PUT or POST etc?

@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.
    }
    
}

How do they both run in the maven life cycle?

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 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>
  • 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 folder resource/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 {

}

What does the above @RunWith do?

@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.
    }
}

Examples in GitHub

spring-boot-integration-test's People

Contributors

authorjapps avatar gozerocode avatar macrocks avatar nirmalchandra avatar officiallysameer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spring-boot-integration-test's Issues

Spring boot + spring Data + h2 in-memory DB = hibernate error

I have used E2eJunitRunner from the sample but it's NOT starting spring app when run as JUnit Test
I have built a REST API with spring boot , Spring data and h2 in-memory.

Get the following error when running the app as JUnit Test. Please advise. thanks
I can run test cases by running build with skip tests and run the boot jar.

you could refer to my code here https://gitlab.com/Sidhaye/springboot/tree/SpringBoot-RestAPI-ZeroCode-Integration

�[0;39m2018-10-16 22:14:10,406 �[32m[main]�[0;39m �[31mWARN�[0;39m org.springframework.web.context.support.GenericWebApplicationContext - �[34mException encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.boot.archive.spi.ArchiveException: Could not build ClassFile

POM enable the SpringBoot-Data-RestAPI-H2Db-ZeroCode project

Objective:
Create a POM version of this project from Sidhaye's GitLab
https://gitlab.com/Sidhaye/springboot/tree/SpringBoot-RestAPI-ZeroCode-Integration

TODO things to resolve this ticket:

  • Request @BeTheCodeWithYou to grant contributor access to us (@authorjapps , @macrocks , @officiallysameer )
  • Add a POM file with exact same dependencies of Gradle file, but use latest version of Zerocode(1.2.x)
  • Add a Suite runner to run all the tests at once
    • Via JUnit Suite class
    • Via Zerocode Package Runner
  • Verify mvn clean install works.
    • Tests are happy
    • Reports are generated
  • Share in the README file(specifying Gradle n POM enabled) and close this.
  • Tweet this link/repo

Basically add a POM file, no code changes needed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.