Digital Innovation: Expert class - Development of unit tests to validate a beer inventory management REST API.
REST API for managing beer stocks. Unit tests were developed to validate the beer inventory management system, and also presented the main concepts and advantages of creating unit tests with JUnit and Mockito. In addition, the development of our API's functionalities was carried out through the practice of TDD.
The following topics were addressed:
- Download a project through Git to develop our unit tests.
- Conceptual presentation on tests: the test types pyramid, and also the importance of each test type during the development cycle.
- Focus on unit tests: show why it is important to develop these types of tests as part of the software development cycle.
- Main frameworks for unit testing in Java: JUnit, Mockito and Hamcrest.
- Development of unit tests for validation of basic functionalities: creation, listing, query by name and exclusion of beers.
- TDD: presentation and practical example on 2 important features: increase and decrease in the number of beers in stock.
To run the project in the terminal, type the following command:
mvn spring-boot:run
To run the test suite developed during live coding, simply run the following command:
mvn clean test
After executing the above command, just open the following address and view the project execution:
http://localhost:8080/api/v1/beers
The following prerequisites are necessary for the execution of the project developed during the class:
- Java 14 or higher versions.
- Maven 3.6.3 or higher versions.
- Intellj IDEA Community Edition or your favorite IDE.
- GIT version control installed on your machine.
- A lot of desire to learn and share knowledge :)
Below are useful links:
- SDKMan!for managing and installing Java and Maven
- Intellij IDEA Community Reference, downloadable
- Intellij Command Shortcut Palette
- Spring's official website
- JUnit 5 official website
- Mockito official website
- Official Hamcrest website
- References - testing in general with Spring Boot
- Reference to the REST architectural pattern
- Test Pyramid Reference - Martin Fowler
This link, following the slides presented as the script used for the development of the project of our session.