ITEC 120
Testing methods

Objectives

Improve your understanding of tests by testing some methods that have been written by someone else.

Discussion

Suppose a friend tells you that she has written a class named HandyMethods and that it contains several handy methods you might want to use. One in particular is named times2. She explains that it takes an int and returns an int that is the original int times 2.

Say you were to call her method with the value 1. You would EXPECT the returned value to be 2. Suppose you were to call her method with the value 3. You would EXPECT the returned value to be 6.

So you write the following bit of code:

    HandyMethods srv = new HandyMethods();
    System.out.println("One times two is " + srv.times2(1));
    System.out.println("Three times two is " + srv.times2(3));

You recall that you expected to see certain values, but when you run the code, the ACTUAL values are displayed like this:

    One times two is 7.
    Three times two is 21.

Whoa nelly! That is not at all what you EXPECTED!

The ACTUAL output seems to have FAILED the test-- it is not what you EXPECTED. Before using her code inside your code, maybe it's a good idea to make sure it does what you think it does!

Assignment

Download HandyMethods.class and TestingHandyMethods.java.

Your friend Ms. Brenneman has written the very class referred to in the discussion above. Her friend Dr. Pittges was excited to use those new methods, but he wrote TestingHandyMethods and ran it, and thus he discovered the handy times2 method contained some serious bugs.

Compile and run Dr. Pittges' TestingHandyMethods class.

HandyMethods also contains a method named moreUpperThanLower. It takes a String and returns true if (and only if) the input String contains a larger number of uppercase letters than lowercase letters.

HandyMethods also contains a method named biggestInt. It takes three ints and returns the one with the largest value.

It turns out that Ms. Brenneman was loopy from WAY too much grading on the day that she wrote HandyMethods, and each of her three methods contain a bug! Your job is to write some tests that Ms. Brenneman can use to discover how her code isn't working so she can go back and fix that buggy code!

For each test you write, indicate whether the test PASSES (the ACTUAL output matches the EXPECTED output) or it FAILS (the ACTUAL output is not what you EXPECTED).

When you have written and run your tests and you have figured out the bug in each of the three methods, create a file named Bugs.txt. In it, type a short but precise description of the bug in each of the three methods. This will be submitted along with your source code.

Submit Your Assignment

Submit your TestingHandyMethods.java and Bugs.txt files to the Lab Submission Folder on D2L.