This repository contains a simple spring boot
web application for creating clients and services.
The information presented here is to demonstrate how you test various aspects of your spring boot
application such as data access objects
, services
, controllers
and utility classes
.
It also demonstrates concerns such as unit tests
, test slices
, integration tests
and mocks
.
There are two branches in this repository:
complete
: this contains the complete project with test casesinitial
: this does not contain any test cases
.
|__src/
| |__main/
| | |__java/
| | | |__com/juliuskrah/demos/springboottestingtraining/
| | | | |__SpringBootTestingTrainingApplication.java
| | | | | |__controller/
| | | | | | |__ClientController.java
| | | | | |__dto/
| | | | | | |__ClientWithServices.java
| | | | | | |__ServiceDto.java
| | | | | |__model/
| | | | | | |__Client.java
| | | | | | |__Service.java
| | | | | | |__ServiceSetting.java
| | | | | | |__ServiceSettingId.java
| | | | | |__repository/
| | | | | | |__ClientRepository.java
| | | | | | |__ServiceRepository.java
| | | | | | |__ServiceSettingRepository.
| | | | | |__service/
| | | | | | |__ClientService.java
| | | | | | |__ClientServiceImpl.java
| | |__resources/
| | | |__db/
| | | | |__changelog/
| | | | | |__db.changelog-master.yaml
| | | | |__data/
| | | | | |__client.csv
| | | | | |__service.csv
| | | | | |__service_setting.csv
| | | |__application.properties
| |__test/
| | |__java/
| | | |__com/juliuskrah/demos/springboottestingtraining/
| | | | |__SpringBootTestingTrainingApplication.java
| | | | | |__controller/
| | | | | | |__ClientControllerTest.java
| | | | | |__repository/
| | | | | | |__ClientRepositoryTest.java
| | | | | | |__ServiceRepositoryTest.java
| | | | | | |__ServiceSettingRepositoryTest.java
| | | | | |__service/
| | | | | | |__ClientServiceTest.java
| | | | | | |__CompanyServiceTest.java
| | |__resources/
| | | |__application.yaml
|__pom.xml
repository
: contains thedata access objects
model
: contains thedomain objects
controler
: contains the anotated controllersservice
: contains thebusiness objects
dto
: contains thedata transfer objects
- Unit tests
- slice tests
- testcontainers
- mockito:
@mock
,@mockBean
,@spy
- wiremock
- Integration tests
- @SpringBootTest
- Maven failsafe plugin
test
: Using Surefire pluginverify
: using Failsafe plugin
- Don't test framework code
- Reuse application context or Dirties Context
@Transactional
ArgumentCaptor
- Testing exceptions