Skip to content
Ameen Abozaid
Planned lessonJNR-016-L06

Demo: test-driving a controller with @WebMvcTest

  • Lesson 6 of 7
  • Junior
On This Lesson 3 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

write tests first for GET /products/{id}; prepares JNR-016-LAB1.

Draft outline details

Step by step

  1. Write a failing test for the success case; mock the service; assert status and JSON fields.
  2. Make it pass (the controller from JNR-013).
  3. Add a validation test: POST /products with a blank name returns 400 and a field error.
  4. Planned mistake: assert only status().isOk(), and a bug in the JSON passes. Fix: add jsonPath assertions.
  5. Add the not-found test and check the Problem Details body.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.