3. 3
Confidential
● 6 years at GL
● Trainer & Mentor at GL Training Center
● Works with Microservice architecture based on Spring and
Spring Boot, Gradle & Docker with AWS
About myself
4. 4
Confidential
● Why Spring Boot for REST
● Why bother write tests?
● Spring Test Framework Overview
● Reviewing Test Results
Agenda
9. 9
Confidential
● Based on Spring MVC
● JSON/XML/Hypermedia Support
● Annotations like @RestController, @ResponseBody, @RequesBody
● RestTemplate
Spring Rest Support
10. 10
Confidential
● Create stand-alone Spring applications
● Embed Tomcat, Jetty or Undertow directly (no need
to deploy WAR files)
● Easy Dependency Management & Automatically
configure Spring and 3rd party libraries whenever
possible
● Provide production-ready features such as metrics,
health checks and externalized configuration
Spring Boot features
19. 19
Confidential
● Understanding of requirements
● Refactoring insurance
● Documenting features
● Improving API
● Reducing errors
● Confirming code is working on
review
Advantages to dev
21. 21
Confidential
● You are not allowed to write any production code unless it is to make
a failing unit test pass.
● You are not allowed to write any more of a unit test than is sufficient to
fail; and compilation failures are failures.
● You are not allowed to write any more production code than is
sufficient to pass the one failing unit test.
The Three Laws of TDD
24. 24
Confidential
The goal of unit testing, is to validate that each unit of
the software performs as designed. A unit is the
smallest testable part of any software.
Goal of Unit Testing
25. 25
Confidential
The goal of integration testing, is to test whether many
separately developed modules work together as
expected
Goal of Integration Testing
26. 26
Confidential
● Give us confidence that the code does what it
should.
● Provide feedback that is fast, accurate, reliable and
predictable
● Make maintenance easier, something that is
commonly overlooked when writing tests.
As summary
31. 31
Confidential
Once the TestContext framework loads an
ApplicationContext (or WebApplicationContext) for a
test, that context is cached and reused for all
subsequent tests that declare the same unique context
configuration within the same test suite.
Context Caching
33. 33
Confidential
● Using profiles wisely
● Reconsidering usage of @MockBean
● Thinking carefully about @DirtiesContext
● Using test slices - @WebMvcTest & @DataJpaTest,
etc
● Using class inheritance
● Refactoring into unit tests
Spring Test Performance Optimization
37. 37
Confidential
● curl and http request snippets are generated
● easy to package documentation in projects jar file
● easy to add extra information to the snippets
● supports both JSON & XML
● keep up docs with your up-to-date functionality
● encourage to work by TDD
Spring Rest Docs