As you start writing new code, you don't want to fall into the same trap as the legacy code you have to deal with. You want this new code to have tests in order to verify changes to it either as the next step in your refactoring or in some future refactoring. With Test-Driven Development ( TDD) you actually make sure you write the tests before you write the code. Let's have another look at our Model View Presenter (MVP) refactoring.
When separating out business logic code from the GUI (Graphical User Interface) we're now able to write tests to verify that business logic independent of the user interfaces tests that can be automated much easier. Before we refactored CreateInvoiceForm
, we knew we needed the presenter to create an invoice based on information in the view as well as construct a presenter based on a specific view. In this case, we want two tests: one to test that the presenter is created correctly with the correct view reference, and one to verify that...