From the course: Spring: Test-Driven Development with JUnit

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Write unit tests for @Controller

Write unit tests for @Controller

From the course: Spring: Test-Driven Development with JUnit

Start my 1-month free trial

Write unit tests for @Controller

- [Instructor] Let's now look at how we might write some unit tests for spring controller component, but first let's review our unit test objectives. We're going to be writing a contact management unit test class where we're just testing adding a contact. And we isolate our test to just the contact management controller which means we're going to mock out our contact management service. There will be a bit of setup as usual. So just to preview what that is, we will need to mimic or mock some web browser behavior. We want to instruct our test environment to load our controllers. We also want to instruct our test environment to just load mocks for our service components or anything else beyond a service layer. So let's get started. Here in our Spring project, I'm going to go into our source test Java Tree and go to our controller package and I want to open up the contacts management controller unit test. And let me double click to expand this window. And let's walk through a little bit…

Contents