1 / 35

Intro to Java Week 12 (Slides courtesy of Charatan & Kans, chapter 8)

Intro to Java Week 12 (Slides courtesy of Charatan & Kans, chapter 8). Software Quality. Learning objectives. By end of this lecture you should be able to:. document your code so that it is easy to maintain; distinguish between compile-time errors and run-time errors;

Download Presentation

Intro to Java Week 12 (Slides courtesy of Charatan & Kans, chapter 8)

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. Intro to Java Week 12 (Slides courtesy of Charatan & Kans, chapter 8)

  2. Software Quality Learning objectives By end of this lecture you should be able to: • document your code so that it is easy to maintain; • distinguish between compile-time errors and run-time errors; • test a program using the strategies of unit testing and integration testing; • generate test data using the strategies of black box testing, white box testing and stress testing; • document your test results professionally using a test log; • explain the meaning of a Java program throwing an exception; • format your output to improve the usability of your programs.

  3. Measuring quality • There are many desirable features of a piece of software. • We will concentrate on the following: • maintainability; • reliability; • robustness; • usability.

  4. Maintainability • The requirements of an application often change over time. • Maintaining a system refers to the need to update an existing system to reflect these changing requirements. • Code should be designed in such a way as to make these changes easier rather than harder.

  5. Documentation • For a software system to be easy to maintain, the software design also needs to be clearly documented. • When developing object-oriented programs, this design documentation should include: • complete class diagrams; • clear method definitions (parameter & return types, plus pseudocode when appropriate).

  6. Reliability • When attempting to run a program two kinds of errors could occur: • compile time errors; • run-time errors.

  7. Compiler errors

  8. Testing • Testing can never show the absence of errors, only the presence of them. • The aim therefore of any testing strategy is to uncover these errors. • Two areas of testing: • validation (making sure you are building the right product); • verification (making sure you are building the product right).

  9. Verification • A Java application typically consists of many classes working together. • Testing for such errors will start with a process of • unit testing (testing individual classes) • followed by • integration testing (testing classes that • make up an application together).

  10. Unit testing • All applications require a class with a main method before they can be run. • Two possibilities • add a main method into the class you are testing; • writing a separate class especially to contain the main method. This new class then acts as the driver for the original class.

  11. Dummy classes • Testing theStudentListclass requires theStudentclass to be available. • You can develop your own dummy class in place of the missing class. // a dummy student class class Student { // no code in class }

  12. Adding dummy methods to dummy classes public double findStudentAverage (int i) { return student[i-1].calculateAverageMark( ); } class Student // ammended dummy class { // additional dummy method public double calculateAverageMark() { return 50.5; } }

  13. Integration testing • When the individual classes in a program have been tested they can be integrated and tested together. • If compiler errors occur during integration then check the following:

  14. StudentList x = student[i-].calculateAverageMark( ) Student Student (…) getName( ) setName(…) ? All methods called should have an implementation in the receiving class

  15. Student double calculateAverageMark( ) StudentList x = student[i-1].CalculateAverageMark() ? Names of method calls should match exactly names of methods in receiving class

  16. Student double calculateAverageMark( ) StudentList x = student[i-1].calculateAverageMark(2) ? Parameter list of method call should match exactly parameter list of methods in the receiving class

  17. Student double calculateAverageMark( ) StudentList int x; x = student[i-1].calculateAverageMark(); The expected type of values returned from the method calls should match the return types of these methods in the receiving class. ?

  18. component to test ? inputs expected outputs Black box testing

  19. Testing the method getGrade

  20. 79, 64, 55, 46, 33, 25, -40, 120 grade 'F' grade 'B' grade 'C' grade 'D' grade 'E' "mark too low" grade 'A' "mark too high" Test data produced

  21. Testing the boundaries • If the code still fails to produce the correct result often the error lies on the boundaries of such equivalent groups. • In this case the following boundary values should all be tested as well as the sample from each equivalent group identified earlier: • -1, 0, 1, 29, 30, 31,39, 40, 41,49, 50, 51,59, 60, 61, 69, 70, 71, 99, 100, 101

  22. component to test topMark = 70; // more code here while(!valid) { if (mark > topMark) grade = 'A'; //more code here else valid = false; } inputs based on code expected outputs White box testing

  23. The test log

  24. Robustness A program is said to crash when it terminates unexpectedly. A robust program is one that doesn't crash even if it receives unexpected input values. Generally, whenever a value is received to be processed, it should be checked before processing continues; if an unexpected value could cause the program to crash.

  25. PushToLimitSalesStaff for (int i = 1; i<=3; i++) { System.out.println ("enter sales for employee "+ i); value = EasyIn.getInt(); cars4U.setFigure(i, value); } 'i' set to 3 last time round the loop SalesStaff public void setFigure(int numberIn, int valueIn) { staff[numberIn-1] = valueIn; } an attempt will be made to access index 2 A program will crash if an illegal array index is used

  26. Dealing with the problem public boolean setFigure(int numberIn, int valueIn) { if (numberIn <= staff.length) { staff[numberIn-1] = valueIn; return true; // method succesful } else { return false; // method unsuccessful } }

  27. Adapting the driver program for (int i = 1; i<=3; i++) { System.out.println ("enter sales for employee "+ i); value = EasyIn.getInt(); boolean ok = cars4U.setFigure(i, value); if (!ok) // unable to set figure succesfully { System.out.println ("ERROR:last figure not entered "); } }

  28. Usability • The usability of a program refers to the ease with which users of your application can interact with your program. • A user-manual can help make your programs easier to follow.

  29. Adding a "HELP" option • *** REACTOR SYSTEM *** • [1] Get current temperature • [2] Increase temperature • [3] HELP • [4] Quit • enter choice [1,2,3,4]: _

  30. Escape sequences • Special formatting characters, known as escape sequences, can be added into strings.

  31. The DecimalFormat class The DecimalFormat class can be used to format the display of decimal numbers. This class resides in the java.text package import java.text.*; Once you have access to this class you can create DecimalFormat objects in your program.

  32. Creating DecimalFormat objects • TheDecimalFormatconstructor has one parameter, the format string. DecimalFormat df = new DecimalFormat( "000,000.000");

  33. Using a DecimalFormat object • Use the format method of the DecimalFormat class to format a given number: DecimalFormat df =new DecimalFormat( "000,000.000"); double someNumber = 12345.6789; System.out.println("before\t" + someNumber); System.out.println("after\t"+ df.format(someNumber)); before 12345.6789 after 012,345.679

  34. Optional digits • Replacing a zero in a format string with a hash (#) would mean that the digit was optional, not compulsory. DecimalFormat df = new DecimalFormat( "#00,000.000"); double someNumber = 12345.6789; System.out.println("before\t" + someNumber); System.out.println("after\t" + df.format(someNumber)); before 12345.6789 after 12,345.679

  35. Graphical user interfaces

More Related