JUnit tests are standard in most software projects. Unfortunately test automation often ends on the unit test layer. It doesn't have to be like this! The Spring Boot framework provides useful tools for implementing integration and system tests. This presentation shows best practices on how to implement unit, integration and system tests using JUnit 5 and Spring Boot test support. The presentation is accompanied by a sample project, which can be found at https://github.com/britter/bootify-testpyramid.
2. WHO IS THIS GUY?
Software Crafter
Java & Scala Guy
Open Source Enthusiast
IT Consultant
Podcaster: http://autoweird.fm
Social Media:
2
@BenediktRitter
github.com/britter
3. AGENDA
3
Test Types in Web Apps
My View of State of the Art Testing
Test Pyramid
Short Recap of Test Pyramid
Demo
Let’s look at some Code!
Conclusion
What have we learned today?
Discussion / Q&A
Anything else you want to know?
Bootify Your Test Pyramid
4. 4
The test pyramid is a concept developed by Mike Cohn, described
in his book Succeeding with Agile. Its essential point is that you
should have many more low-level unit tests than high level end-to-
end tests running through a GUI.
Source: https://martinfowler.com/bliki/TestPyramid.html
Short recap of the Test Pyramid
INTRODUCTION
5. Test Kinds
5
System Test
Unit Test
Integration Test
Smoke Test
Penetration Test
Performance Test
Acceptance Test
Feature TestUI Test
Component Test
Module Test
8. 7
TEST TYPES IN WEB APPS
My View of State of the Art Testing
This model of different test types and was inspired by the „Crafting Code“ Workshop by Sandro
Mancuso. Sandro has a very pure and reduced approach for creating application which doesn’t
require a lot of frameworks. I adopted his technique of testing different parts of application to
leverage Spring Boot testing support. A video of Sandro doing Outside-In TDD can be found here:
https://www.youtube.com/watch?v=XHnuMjah6ps
31. Bootified Test Pyramid
11
System Test
Unit Test
Integration Test
JUnit 5, assertJ
Builders & Templates
@DataJpaTest & TestEntityManager
@WebMvcTest & MockMvc
32. Bootified Test Pyramid
11
System Test
Unit Test
Integration Test
JUnit 5, assertJ
Builders & Templates
@DataJpaTest & TestEntityManager
@WebMvcTest & MockMvc
@SpringBootTest
33. 12
DEMO
Let’s work with Orders
Web application managing orders. It provides an HTTP interface for
creating and retrieving orders. When creating an order, a delivery price
is calculated based on the total weight of that order. The delivery price
is persisted along side the order data inside a RDMS for reporting.
Code: https://github.com/britter/bootify-testpyramid
34. 13
CONCLUSION
What have we learned today?
There are different types of tests for each layer of an application. A well
defined domain model together with templates can help tremendously
setting up tests on each layer. Spring Boot provides the necessary
infrastructure to easily write Integration and System Tests.
35. Working with security, e.g. @MockUser
1
Integration tests against middlewares like
message queues
System tests using Test Containers
Custom assertJ assertions
Other test types, for example acceptance
tests using Cucumber
2
3
4
5
NOT COVERED TODAY
14
There is more!