When working through one of our Java courses, you might have come across an exercise that had two files: Unit Test and Scratchpad.java. 

What is the Scratchpad?

Scratchpad.java is a special file that only exists for Unit Test programs. It's designed as a place for your students to play around with the code they write before submitting their solution.

What should I write in Scratchpad.java?

The Scratchpad is designed for you to copy your Unit Test method and run some tests on it to see if it works the way you expect it to.
For example: you're working on 3.3.4 Double Number, a Unit Test in our AP Computer Science in Java course. The exercise asks that you write a method that takes an integer and returns that integer doubled. Easy enough! But what happens if you pass a negative integer? Or zero? Let's go to the Scratchpad to find out!

We've copied doubleNumber from our Unit Test file into Scratchpad.java  and written some primitive tests.
Hit Run Scratchpad and see if the code behaves how you expect!

Our output looks like what we'd expect, so we can copy the code back to the Unit Test file and submit confidently.

What else can I do?

It's not too much work to create more robust tests with good names and messages.
Here's an example of a more fully realized test suite:

There's a lot that can be done in Scratchpad. If you have any cool ways of testing your Unit Tests, let us know!

Did this answer your question?