课程: Complete Guide To Java Testing with JUnit 5 & Mockito

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

Refactor tests to ensure maintainability

Refactor tests to ensure maintainability

- [Instructor] We've implemented two classes, task manager and task using test-driven development, where we've written the tests before we've written the code. We've completed the requirements for the project, but now let's review our code and see if there's anything we can improve. We'll start off with our task manager test. Here we create a new task manager with every single test. Let's use a before each annotation and create a task manager for the entire class. Before each test method, we'll run the setup where we set the task manager to be a new instance. This will replace the task manager used in each test. With this re-consolidation and re-naming, it makes it clear exactly what we're testing. Given most of our tests, use at least one task, we can also set up a task in our setup method. Let's replace the task references in the rest of our class with this task. In this case, the task description doesn't really matter because it's not used in any of the assertions. This means we…

内容