Unit Testing - what does "unit" mean there? Is it a public method? A class? 2 classes? No. It's a "unit of behavior" says Kent Beck, the author of JUnit and inventor of Unit Testing. It's the thinnest slice you can isolate from a full feature, ideally end-to-end. On the other hand, it's easier to write fine-grained tests covering a single method or a class, but they won't provide you the same degree of safety as larger end-to-end automated tests. That's why we should aim to to cover as much code possible with isolated, repeatable and reasonably fast tests, while also keeping them simple and maintainable. But that's hard. It's one of the most difficult task for any developer, no matter how experienced.
After discussing unit testing for hundreds of hours in dozens of companies, I found that the biggest challenges for most teams is to identify the risks in their code, and then to master the testing tools to cover that code with simple, effective tests. Tests that really help you catch bugs and save you time, while not impeding future refactoring. During this course you will learn techniques to bring more of your application under tests by making best use of the Spring Framework's testing support.
This is the recording of a 4-hours live webinar that took place in September 2020 with 26 live participants. The content is extremely dense, mixed with explanations of how the Spring Framework works internally.
During this training you will learn:
- Best ways to test flows interacting with a relational database: external, in-memory and running in a local Docker
- Test-driving dynamic queries underlying search forms (TDD), and using a .feature file approved by business (BDD)
- Best practices when testing with files, nosql or other non-transacted resources: when/how to clean-up
- Using a fake test implementation
- The problem with caches
- How to control time from your tests
- Best ways to test flows calling external services: @MockBean vs WireMock (file-based or programatically)
- Testing your REST API: should you? and how?
- Black-box testing in-JVM: emulated HTTP calls and embedded Spring Boot server
- Black-box testing your application deployed in a local Docker
- JUnit 5 features that help you keep your integration tests clean
Every single technique we cover can run on your CI Jenkins pipeline!
What to expect?
During the training we write automated tests for 3 simplified examples of production code, for each one trying out and comparing various testing strategies. Below you can find a diagram summarizing all topics covered in detail.
Each working alternative was carefully committed to a git that you will get access to. Even if it's 90% code, the discussion insists on principles, best practices and pitfalls of the solutions we implement, and acknowledges that you can google up additional details afterwards about the deeper topics we touch upon (Docker, WireMock). After watching the video, I will insist you ask me any kind of question you have related to what we covered.
After following this course, you'll take away at least a dozen of key practical techniques that you can immediately apply to your day-to-day work. Expect an intense but entertaining experience, as usual!
Java developers with prior contact with Spring Framework, or otherwise extremely eager to learn it. Basic knowledge of a mocking framework (like Mockito) is also useful.
To be able to run the code locally, your machine should have a Java 11+ SDK installed, Docker, and access to Maven Central. If you want to directly replicate my actions, download and install IntelliJ Community Edition, as I occasionally used some of its specific features.
After purchase, besides video recording and slides, you will be able to download the final code zipped together with the git history, allowing you to browse through the commits at your own pace.
Here are some resources you could use to learn more about the techniques we use in the training:
P.S.: The content is distilled from my 2-days (16-hours) Unit Testing training. If you are interested in a private dedicated session for your company, please find here my entire curricula and contact details.
Below is a master overview of all that we cover in the course. The blue arrow denote the tests we wrote and the red rectangles are the techniques we used: