Guided Project: Test-Driven Development with JUnit 5 in IntelliJ IDEA
Build a shopping basket with an offer and a discount code test-first, in short red-green-refactor cycles, with JUnit 5 and IntelliJ IDEA.
Guided project, Intermediate · Software Development · about 2 hours · 1 module · certificate on completion
Taught by Agnieszka Kowalskà, AI Learning Companion.
About this course
In this guided project you'll build a small but realistic piece of software, a shopping basket with a buy-three-pay-for-two offer and a discount code, entirely test-first. You'll write each test before the code that makes it pass, watch it fail, make it pass with the simplest code you can, and then tidy up with the tests protecting you: the red-green-refactor cycle of test-driven development. IntelliJ IDEA does much of the typing, creating classes and methods from the tests that use them and refactoring safely. Three short lessons explain the cycle and the habits that make it work; then the lab takes you through the basket one cycle at a time, to a suite of passing JUnit 5 tests that you submit for your instructor's review.
What you'll learn
- Work in red-green-refactor cycles: a failing test first, then the simplest code that passes it, then a clean-up
- Let IntelliJ IDEA create classes and methods from the failing tests that use them
- Write focused JUnit 5 tests, including parameterised tests and tests that expect exceptions
- Refactor with your tests as a safety net, using IntelliJ IDEA's automated refactorings
Skills you'll gain
Test-driven development, JUnit 5, Refactoring, IntelliJ IDEA, Java, Maven
Tools
IntelliJ IDEA, JUnit 5, Maven
Before you start
Some Java (classes, methods, lists and maps) and the basics of JUnit 5, as a beginner Java course teaches them. IntelliJ IDEA (the free version is enough) and a JDK of version 21 or later, which IntelliJ IDEA can download for you; Maven comes with IntelliJ IDEA.
Modules
Build a shopping basket test-first
Learn the red-green-refactor cycle and how to choose, write and refactor tests, then build a Basket class test-first with JUnit 5 in IntelliJ IDEA.
- The red-green-refactor cycle (9 min)
- Choosing and writing good tests (8 min)
- Refactoring under green tests (8 min)
- Hands-on lab: Build a shopping basket test-first
IntelliJ IDEA is a trademark of JetBrains s.r.o. This course is independent: JetBrains hasn't made or endorsed it.