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

Slides:



Advertisements
Similar presentations
Testing Relational Database
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Software Testing. Quality is Hard to Pin Down Concise, clear definition is elusive Not easily quantifiable Many things to many people You'll know it when.
P5, M1, D1.
Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
1 Software Engineering Lecture 11 Software Testing.
© The McGraw-Hill Companies, 2006 Chapter 15. © The McGraw-Hill Companies, 2006 Exceptions an exception is an event that occurs during the life of a program.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
FIT FIT1002 Computer Programming Unit 19 Testing and Debugging.
Java Programming, 3e Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
November 2005J. B. Wordsworth: J5DAMQVT1 Design and Method Quality, Verification, and Testing.
Integration testing Satish Mishra
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
© The McGraw-Hill Companies, 2006 Chapter 9 Software quality.
Software Development Study Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
IMSE Week 18 White Box or Structural Testing Reading:Sommerville (4th edition) ch 22 orPressman (4th edition) ch 16.
Chapter 1 Program Design
ECE122 L17: Method Development and Testing April 5, 2007 ECE 122 Engineering Problem Solving with Java Lecture 17 Method Development and Testing.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
1 Joe Meehean. 2 Testing is the process of executing a program with the intent of finding errors. -Glenford Myers.
1 Functional Testing Motivation Example Basic Methods Timing: 30 minutes.
Ranga Rodrigo. Class is central to object oriented programming.
System/Software Testing
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
Chapter 12: Exception Handling
Abstract Data Types (ADTs) and data structures: terminology and definitions A type is a collection of values. For example, the boolean type consists of.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Prologue: The Software Process. Main Phases of Software Process 1. Requirements Analysis (answers “WHAT?”) Specifying what the application must do 2.
Software Engineering CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Lecture 2: Classes and Objects, using Scanner and String.
Arrays, File Access, and Plotting
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
© 2006 Pearson Education 1 More Operators  To round out our knowledge of Java operators, let's examine a few more  In particular, we will examine the.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
22/11/ Selection If selection construct.
CSC Programming I Lecture 6 September 4, 2002.
The Software Development Process
Java Programming, 2E Introductory Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
Software Engineering Issues Software Engineering Concepts System Specifications Procedural Design Object-Oriented Design System Testing.
Copyright © 2000, Department of Systems and Computer Engineering, Carleton University 1 Introduction An array is a collection of identical boxes.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
31/01/ Selection If selection construct.
Chapter 6 - More About Problem Domain Classes1 Chapter 6 More About Problem Domain Classes.
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Exception Handling How to handle the runtime errors.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
Programming in Java (COP 2250) Lecture 12 & 13 Chengyong Yang Fall, 2005.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 10 Using Menus and Validating Input.
© 2006 Pearson Education Chapter 3 Part 2 More about Strings and Conditional Statements Loops (for and while) 1.
Working with Java.
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Objectives You should be able to describe: Interactive Keyboard Input
CS1101X Programming Methodology
UNIT-4 BLACKBOX AND WHITEBOX TESTING
CSE 1020:Software Development
Review of Previous Lesson
CHAPTER 6 Testing and Debugging.
UNIT-4 BLACKBOX AND WHITEBOX TESTING
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 the StudentList class requires the Student class 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 All methods called should have an implementation in the receiving class Student Student (…) getName( ) setName(…) StudentList x = student[i-].calculateAverageMark( ) ?

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

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

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

18 Black box testing component to test ? inputsexpected outputs

19 Testing the method getGrade

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

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 White box testing component to test inputs based on code expected outputs topMark = 70; // more code here while(!valid) { if (mark > topMark) grade = 'A'; //more code here else valid = false; }

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

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 The DecimalFormat constructor has one parameter, the format string. DecimalFormat df = new DecimalFormat( "000, ");

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

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, "); double someNumber = ; System.out.println("before\t" + someNumber); System.out.println("after\t" + df.format(someNumber)); before after 12,

35 Graphical user interfaces