Challenge: Unit Test Using Test-Driven Development

Apply what you have learned about making tests more effective by completing a test-driven development exercise.

Introduction

In this project, you’ll write a unit test that tests the behavior of a class using the test-driven development approach. An assessment rubric is provided to guide you on whether or not you’ve applied the principles taught in this chapter.

Self-assessment rubric

I have… Emergent Satisfactory Excellent
Used parameterized tests Did not use parameterized tests Partially used parameterized tests Used parameterized tests for test methods, wherever appropriate
Used a setup method No setup method used N/A Setup method used
Pitched the tests at the right level Inconsistent test approach—a combination of high-level and detailed approaches used N/A Consistent test approach—either a high-level or detailed approach adopted
Followed a TDD approach Wrote the application code first and then the test code Wrote bits of application and test code at the same time Wrote the test code first followed by the application code

Project requirement

Write the application code that contains a calculator class that performs the following functions:

  • Return the maximum of both parameters.
  • Return the minimum of both parameters.
  • Given a number, returns a list of all odd numbers between zero and the provided number.
  • Given a number, return the number of odd numbers between zero and the provided number.
  • Given a number, determine whether that number is odd or not.

The interface requirements for the functions are as follows:

  • Max method: Integer parameters and an integer return value.

  • Min method: Integer parameters and an integer return value.

  • Return odd numbers method: Integer parameter and list of integers as the return value.

  • Return number of odd numbers method: Integer parameter and an integer return type.

  • IsOdd number method: Integer parameter and a boolean return type.

Get hands-on with 1400+ tech skills courses.