Kotlinlearncs.online LogoJava
Return to List

Test Writing: Test Rotate String

Created By: Geoffrey Challen
/ Version: 2020.10.0

Declare a public class TestRotateString with a single void static method named testRotateString. testRotateString receives an instance of RotateString as a parameter, which has a single method rotate. rotate takes a String and an int as arguments, and rotates the passed string by the passed amount. If the amount is positive, the rotation is to the right; if negative, to the left. If the String is null, rotate should return null.

Your testRotateString method should test the passed implementation using assert. Here's an example to get you started:

As you create your test suite, consider the various kinds of mistakes that you might make when implementing rotate. Maybe getting the direction wrong, or using the modulus improperly? There are lots of ways to mess this up! You need to catch all of them. Good luck!

Test Design Challenge

You're challenge is to write tests for this problem described above.

  • Provide a public class named TestTestRotateString with a single non-private class method named test that accepts no arguments and does not return a value.
  • If the implementation of the class described above is incorrect, your test method should throw an exception.
  • If it is correct, do not throw an exception.
  • You may want to use Java's assert method