



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Announcements Read section 6.4. No class Friday Testing Last time we started looking at testing. We did some unit testing of a prototype of an electronic diary. What is unit testing? Unit Testing tests smaller pieces of the code (such as a method). Units can be items such as a class, a group of classes, or even a single method. Unit testing can be performed long before the application is complete. What techniques did you use to use when you were unit testing the diary?
How would you have gone back and run your one-hour tests? Well, if you have to do it by hand, it is tedious and unlikely to get done. Imagine if you were testing something with 10,000 lines instead of 50. So, we want to automate the testing process so it is easier to run regression tests. Let's look at the diary-testing project. Class OneHourTests automates some of the tests that we did earlier. For example, the method makeThreeAppointments makes an appointment at the beginning of the day, at the end of the day, and in the middle of the day. Let's write a TwoHourTests class. What does it need to do? How do we fix some of these problems? OK, so now we can easily rerun all of our tests after we change the code. Is there anyway that this could be better? Well, we still have to examine the results by hand. If there are lots of tests, this will be time consuming and error-prone. Also, note that if there is a java exception, the test stops executing. We can't run all of our tests until we fix the problem. Automated Checking of Test Results It would be nice if we could automate the checking of test results when we do regression testing. BlueJ supports this with the Junit testing framework. Open the diary-testing-junit-v1 project. What's different? Well, first of all there is this funny class DayTest, which is identified as a unit test class. We also need to re-configure BlueJ: Select Tools | Preferences | Miscellaneous. Select the Show unit testing tools option. You should now see some extra buttons below the compile button in the main BlueJ window. Press the Run Tests button. What happened? (Can all select Run All from the right click menu associated with the DayTest class) We can also run just one of the tests. So, where did this class come from? Well, BlueJ created it for us, automatically!
Now we have a test. Let's execute it. Let's look at the source code. Let's write a test that checks to make sure that we can't schedule a 2-hour appointment that begins only 1-hour before a different appointment. What do we need to do? Create a Day object Create an Appointment and Schedule it for 10 AM Create a 2-hour appointment and Schedule it for 9AM Let's write a test for the Appointment class. We want to write a test that makes sure that Appointment objects are initialized correctly when we create them.
Lab 27 Open the triangle-junit project. In this lab, I want you to create some unit tests for the Triangle class. The Triangle class includes: