- Overview
- About the application
- Environment prerequisites
- Build instructions
- About integration testing
- Instructions
This repository is intended to provide a sample Spring Boot project for those who wish to learn and practice integration testing. The main idea is to provide a “playground”, so that whoever makes use of this repository only focuses on implementing tests without worrying about developing the functionality of the application. Explanations will be provided on the importance of integration testing, as well as examples and proposed exercises to practice.
This sample project is a simple Spring Boot project emulating a music store. It exposes REST APIs to execute CRUD operations over resources like Artists, Albums and Songs.
It uses an in-memory database called H2, so you'll find pre-existing data examples.
- Install JDK 21
- Fork this repository
- Once fork is complete, clone the repository.
- Open the project with your favourite editor/IDE (Eclipse, VSCode, IntelliJ, etc.).
- Open a new terminal, move to the project's location and execute the command
.\gradlew clean buildand wait for completion - Finally, execute the application using your editor/IDE or executing
.\gradlew bootRun
If you want to verify application is running you can open the: Swagger documentation
You should see something like this:
Here, you'll find the resources to execute CRUD operations for Artists, Albums and Songs. For example, you can get the lists of artists:
- In the artists section look for the GET API "Returns a paginated list of artists", click on it and then click on the
Try it outoption.
- Then click on
Executeoption.
- You should see a list of artists
Integration Testing is a form of testing focused in testing interactions between internal and external components, but not as a whole system or flow. Some examples of external components are databases, external services, files, etc. Unlike unit tests, integration tests don't simulate or mock interactions with external components, allowing to catch bugs that can't be caught with unit tests.
One disadvantage that integration tests have, is that they're more complicated to execute since previous configuration is needed in order to interact with the external components. They're slow and takes more time to execute them.
In this demo project will be focusing on writing integration tests to test the persistence layer (repositories) and presentation layer (controllers).
As mentioned before, we'll focus on testing persistence and presentation layers. To write and execute the tests, we'll make use of a library called JUnit and we'll use an assertion library called AssertJ, Below you'll find a list of explanations and proposed exercises, please follow them in that order.
💡 IMPORTANT
We'll be working on the
mainbranch but if you take a look, there's another branch calledending_branchthis branch contains more implementation examples for the suggested exercises, you can use this branch to compare it with your tests in case you get stuck, but ideally you should try to solve the exercises by your own by making google searches and investigating so you can really develop an understanding of the subject.
- Testing
ArtistController - Testing
AlbumnController- same instructions asArtistController - Testing
SongController- same instructions asArtistController




