Demo Spring Boot project with JUnit 5 Tests. It includes integration test (for controller) and unit tests (for service and simple class).
- Spring Boot (spring-boot-starter-web, spring-boot-starter-tomcat, spring-boot-starter-test)
- Java 8
- Tomcat 8.5.x
- Maven
- JUnit 5
- Controller: is the presentation layer where the end points are located
- Service: is the service layer where the business logic resides
- Repository: is the persistence layer where the CRUD repository is located
- Integration Test (for the Controller): it uses mockMvc and Hamcrest matchers
- Unit Test (for the Service): it uses the Mockito framework
- Unit Test (for a simple class) it uses pure JUnit
1. Get user by id. HTTP Method: GET
http://localhost:8080/springbootjunit5/users/1
2. Create a user. HTTP Method: POST
http://localhost:8080/springbootjunit5/users
{
"name": "Carlos",
"age": 29,
"email": "[email protected]"
}
- JUnit 5 Documentation: JUnit 5 documentation + migration guide
- Spring Boot Testing Documentation: Spring Boot section that talks about testing
- Why migrate?: Migration from JUnit 4 to JUnit 5 explanation
- Spring Boot Integration Testing: Integration test example in Spring Boot
- Spring Initializr: To generate the structure of a Spring Boot Project
- JUnit 5 test example
- JUnit 5 MockBean
- Spring Boot Testing
I am Carlos Becerra - MSc. Softwware & Systems. But to tell you the truth, I'd prefer to be a passionate developer. You can contact me via:
Any improvement or comment about the project is always welcome! As well as others shared their code publicly I want to share mine! Thanks!
Copyright 2020 Carlos Becerra
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.