1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Testing in Java

Connected

Exercise

Applying TDD to reverse a number

You've seen Test-Driven Development — now let's apply it! Consider a simple method to reverse an int. If you think in terms of TDD, the first thing you need to do is write a test. Focus on the behavior (input and output) of the method, not on its implementation. This will train you to put the project requirements first.

In the code snippet below, complete the test with the expected output, the expression to obtain the method's actual output, and the expression inside the assertEquals() statement.

Instructions

100 XP
  • Enter the correct reversed value for the input number.
  • Invoke the IntReverser method reverse() to acquire the actual value.
  • JUnit expects the expected/actual values in a specific order. Enter them into assertEquals().