1 / 25

How to test an object –oriented program

How to test an object –oriented program. How to code a main method that tests a class Description

gina
Télécharger la présentation

How to test an object –oriented program

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. How to test an object –oriented program How to code a main method that tests a class Description • When you want to test a class before the classes that are going to use it are finished, you can write a main method in the same class. The main method can then test the other methods of the class by sending typical arguments to them and printing the results on the console • The main method in the example above works because the BookOrder class has set and get methods for all instance variables and a toString method that overrides the one in the Object class

  2. When and how to code method stub • Description • When you’re writing a class or method that calls another method that hasn’t been coded yet, it sometimes makes sense to quickly write a method stub for that method. Then, you can complete the method that you’re working on • A method stub can be written at any of the levels shown in the next slide. But when the stub gets too elaborate, it’s often best to write and test the entire method instead of a stub

  3. The User Email application • The UserEmailFrame class defines the JFrame onject. This object includes a windowClosing method that’s executed whenever the frame is closed • The UserEmailPanel class defines the Jpanel object that’s displayed within the JFrame.

  4. The User Email application • This object includes an actionPerformed method that’s executed whenever a button on the frame is clicked. If the Add button is clicked, this method creates a new User object from the User class and calls the addRecord method of the UserIO class to add the data in the User object to the end of a file • The User class defines the User object • The UsetIO class con tains a static addRecord method that adds the data in a User object to the end of a file.

More Related