Solution: Unit Test Using Test-Driven Development

Learn the solution to the test-driven development challenge and learn from your mistakes.


The lesson presents the solution to the challenge to implement test methods to test the required additional calculator features, followed by the application code that implements these new features.


The project solution is shown in the widget below. Run the widget to see that all tests pass. Five public methods are tested, each with its own series of test cases. As a result, a total of eleven test cases are generated. The Calculator class was first developed using an empty implementation. Thereafter, the test code methods and test cases were written referencing the Calculator class. At that point, although the test code compiled, the unit tests all failed. The application code is then filled in until all test cases pass. The final set of test methods and the application code it tests are presented below:

Get hands-on with 1200+ tech skills courses.