Code Monkey home page Code Monkey logo

spring-boot-tests's Introduction

Maven Surefire Plugin

is designed to run our unit tests. The following patterns are the defaults so that the plugin will detect a class as a test:

  • **/Test*.java
  • **/*Test.java
  • **/*Tests.java
  • **/*TestCase.java

Maven Failsafe Plugin

Designed to run our integration tests. Unlike the Maven Surefire Plugin, the Maven Failsafe Plugin is not a core plugin and hence won't be part of our project unless we manually include it. Detects our integration tests by the following default patterns:

  • **/IT*.java
  • **/*IT.java
  • **/*ITCase.java

Maven commands explained

The following commands will not run the integration tests which contains the above-mentioned patterns.

mvn surefire:test
mvn test

If we want to run our integration tests manually, we can do so with the following command:

mvn failsafe:integration-test failsafe:verify

The following will run both the integration and unit test if maven-failsafe-plugin is mentioned in the pom file.

mvn verify

For scenarios where we don't want to run our integration test (but still our unit tests), we can add -DskipITs to our Maven execution:

mvn verify -DskipITs

@WebMvcTest

This annotation creates a Spring TestContext with only relevant Spring MVC (model-view-controller) components:

  • @Controller and @RestController
  • @ControllerAdvice
  • @JsonComponent
  • Converter, Filter, WebMvcConfigurer

@DataJpaTest

Spring TestContext contains the following components:

  • @Repository or any class extending a Spring Data repository
  • EntityManager and TestEntityManager ??
  • DataSource

Nevertheless, it's still worthing testing the entire JPA entity lifecycle by storing an entity, flushing the EntityManager, and retrieving the entity from the database again. This way, we ensure that Hibernate can destruct and construct our entity objects.

spring-boot-tests's People

Contributors

mehdihasan avatar

Watchers

 avatar  avatar  avatar

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.