/junit-5-how-to

This is an example of JUnit-5 use

Primary LanguageJavaGNU General Public License v3.0GPL-3.0

GitHub CI

codecov

Project title

🚦 junit-5-how-to 🚦

This is an example of JUnit-5 with Spring 🔆

Assumptions

  • This is a sandbox to test JUnit 5 not a real project,
  • There is a small part of DDD (Domain Drive Design) and CQRS (Command Query Responsibility Segregation) inside as well.

Getting started

Class diagram

How to run

  • The project is using SpringBoot thus is possible to iterate using an endpoint or command line interface.

Using java -jar

  • Let's cover 3 ways to interact with the application

CURL

  • GET
    • hello curl http://host:port/hello
    • products curl http://host:port/products
  • POST curl -d '{"title":"my product title", "price":"10"}' -H "Content-Type: application/json" -X POST http://host:port/products

For any doubt, check out the video asciicast

Browser

  • GET
    • hello curl http://host:port/hello
    • products curl http://host:port/products

CLI (Command Line Interface)

* After the application starts a dirty menu will show and press 1 key to create a random product or 2 key to list all products. 
````console
******** CLI MENU **************
* 1 - Create a random product  *
* 2 - Print all products       *
* exit - Turn off CLI MENU     *
********************************
1
2
Product{id='5cac3c8f-342f-4c50-ac30-b404ef755e3a', title='4057b5da-2', price=7}
````

DOCKER

  • Go to the project folder and execute the following commands:

mvn clean verify

docker build -t junit-5-how-to/with-spring .

docker run -it -p 8080:8080 junit-5-how-to/with-spring

If you have any issue with the port, change it.

Follow the video below for any doubt.

asciicast

Author

Luiz Gustavo Costa

Tags

Java, Maven, JUnit 5, Spring, DDD, CQRS, Docker