Skip to content

Understanding the Tests

What does all this mean?!

Tests in Lab 2

Remember to focus on one test at a time!

Before writing any code:

Test output before MysteryClassOne is created. The error reads "java.lang.NoClassDefFoundError: java112/labs1/MysteryClassOne". An annotation on the image identifies the problem: MysteryClassOne is not found. The solution: create the class MysteryClassOne in a package named "java112.labs1".


After creating the class:

Test output after MysteryClassOne is created but before mysteryMethodOne is added. The test "methodOneExistsTest" fails with "java.lang.NoSuchMethodException: java112.labs1.MysteryClassOne.mysteryMethodOne()". An annotation identifies the problem: the test is looking for a method named mysteryMethodOne but it does not exist yet. The solution: create mysteryMethodOne(). The empty parentheses indicate it takes no parameters.

Tip

Did you remember to include a package statement in your class? Did you remember to build after creating the class file?


After adding mysteryMethodOne():

Test output after mysteryMethodOne is added but with the wrong return type. The test "methodOneReturnTest" fails with an AssertionFailedError: "The class must have a method named mysteryMethodOne that returns an int." An annotation identifies the problem: the test expected an int return type. The solution: change the return type of mysteryMethodOne to int.


After changing the return type:

Test output after changing the return type to int but before the method returns the correct value. The test "runMethodOneTest" fails with an AssertionFailedError: "The mysteryMethodOne method must return the value of 1." An annotation identifies the problem: the test expected mysteryMethodOne to return 1. The solution: update mysteryMethodOne so it returns 1.


After changing mysteryMethodOne to return 1, the tests pass!

But remember, we aren’t finished yet. We need to actually run the class after it passes the tests! We still have a little work to do, right?

Terminal output after all tests pass but when trying to run MysteryClassOne directly. The error reads: "Main method not found in class java112.labs1.MysteryClassOne, please define the main method as: public static void main(String[] args)". This means the class compiles and passes tests but still needs a main method to run as a standalone program.