Test-driven development is a popular practice where the developer writes the tests first, knowing they will fail, and then implements the code so that they pass. TDD helps ensure you write well-encapsulated, easily testable code.
Let’s try TDD out now. Below is code for a Rectangle class, as well as a unit test for it. The test is failing right now, though, because the area and perimeter methods are empty. Implement the methods in Rectangle so that the tests pass.
The unit test from the previous exercise has some repeated code for setting up the Rectangle object. Move that code to a setup method within the test class, to eliminate the duplication. (You’ll need to change the local variable that holds the Rectangle to an instance variable.)