Skip to content

Spring Boot Application with MongoDB, and Integration Test with Testcontainers, RestAssured, and JUnit 5

Notifications You must be signed in to change notification settings

drjunior90/testcontainers-restassured-junit5

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Testcontainers, Rest-Assured and JUnit5

This is a Spring Boot project that exposes /customers endpoint and data can be persisted in MongoDB Database.

In the Integration Tests, the Testcontainers Java library is used for starting MongoDB in a Docker container, Rest-Assured is used to interact with the endpoint and JUnit5 as the Test Runner.

How to run Application

Option 1:

Running application from command line using Docker, this is the cleanest way. In order for this approach to work, of course, you need to have Docker installed in your local environment.

  • From the root directory you can run the following command:
    docker-compose -f docker/docker-compose.yml up --build
  • Application will be running on: http://localhost:3101/api/v1/customers
  • To stop it you can press Ctrl + C, and then run the following command:
    docker-compose -f docker/docker-compose.yml down

Option 2:

In case you have mongodb installed locally, and you want to run from IDE

  • Import the testcontainers-demo application as a Maven project to your IDE.
  • Run maven clean install command to build the project.
  • Then you can search for TestcontainersDemoApplication.java class and run it with profile 'dev'
  • Application will be running on: http://localhost:8080/api/v1/customers

Option 3:

In case you don't have mongodb installed locally, and you want to run from IDE

  • Import the testcontainers-demo application as a Maven project to your IDE.
  • Run maven clean install command to build the project.
  • From the command line run the following command to have mongodb running in a docker container:
    docker run -d -p 27017:27017 --name mongodb mongo:4.2.6
  • Then you can search for TestcontainersDemoApplication.java class and run it with profile 'dev'
  • Application will be running on: http://localhost:8080/api/v1/customers

How to run the Integration Test

Option 1:

  • Import the testcontainers-demo application as a Maven project to your IDE.
  • Run maven clean install with profile 'runit' to build the project and start running the IT tests.
    mvn clean install -Prunit

Option 2:

  • Import the testcontainers-demo application as a Maven project to your IDE.
  • Run maven clean install command to build the project.
  • Then you can search for CustomerIT.java class and run it as a junit test.

About

Spring Boot Application with MongoDB, and Integration Test with Testcontainers, RestAssured, and JUnit 5

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published