CS-152: Software Testing

Similar documents
Lab 5: Java IO 12:00 PM, Feb 21, 2018

Assertions, pre/postconditions

Exceptions and Design

Checked and Unchecked Exceptions in Java

CSCI-140 Midterm Review October 10, 2015 Presented by the RIT Computer Science Community

What can go wrong in a Java program while running?

CMSC 202. Exceptions

Exceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages

Principles of Computer Science I

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Object Oriented Programming Exception Handling

Answer Key. 1. General Understanding (10 points) think before you decide.

Do not turn to the next page until the start of the exam.

Errors and Exceptions

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request.

EXCEPTION HANDLING. Summer 2018

CSE 331 Midterm Exam Sample Solution 2/13/12

Java Input/Output. 11 April 2013 OSU CSE 1

Simple Java Input/Output

Exceptions in Java

Introduction Unit 4: Input, output and exceptions

n Specifying what each method does q Specify it in a comment before method's header n Precondition q Caller obligation n Postcondition

Lecture 4: Exceptions. I/O

JAVA REVIEW cs2420 Introduction to Algorithms and Data Structures Spring 2015

Subclassing for ADTs Implementation

A Third Look At Java. Chapter Seventeen Modern Programming Languages, 2nd ed. 1

Chapter 9. Exception Handling. Copyright 2016 Pearson Inc. All rights reserved.

ITI Introduction to Computing II

COMP 213. Advanced Object-oriented Programming. Lecture 17. Exceptions

Day 8. COMP1006/1406 Summer M. Jason Hinek Carleton University

6. Java Errors and Exceptions

CSC Java Programming, Fall Java Data Types and Control Constructs

Exception Handling Introduction. Error-Prevention Tip 13.1 OBJECTIVES

Exception Handling. Chapter 11. Java By Abstraction Chapter 11. Outline What Are Exceptions?

Exception Handling. Chapter 11. Outline. Example: The Quotient app What Are Exceptions? Java By Abstraction Chapter 11

6. Java Errors and Exceptions. Errors, runtime-exceptions, checked-exceptions, exception handling, special case: resources

CS Programming I: File Input / Output

ITI Introduction to Computing II

CS2: Debugging in Java

Exceptions. CSE 142, Summer 2002 Computer Programming 1.

Exceptions. Readings and References. Exceptions. Exceptional Conditions. Reading. CSE 142, Summer 2002 Computer Programming 1.

Name: Class: Date: 2. Today, a bug refers to any sort of problem in the design and operation of a program.

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

Input from Files. Buffered Reader

JAVA BASICS II. Example: FIFO

CS-152: Review. Neal Holtschulte. June 17, 2013

Test suites Obviously you have to test your code to get it working in the first place You can do ad hoc testing (testing whatever occurs to you at

Project #1 Computer Science 2334 Fall 2008

CS Programming I: File Input / Output

CS 3 Introduction to Software Engineering. 3: Exceptions

HST 952. Computing for Biomedical Scientists Lecture 8

CSCI-142 Exam 2 Review November 2, 2018 Presented by the RIT Computer Science Community

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

Software Engineering Testing and Debugging Debugging

While Loops A while loop executes a statement as long as a condition is true while condition: statement(s) Statement may be simple or compound Typical

Remedial Java - Excep0ons 3/09/17. (remedial) Java. Jars. Anastasia Bezerianos 1

Today s Topic. Software Engineering Testing and Debugging Debugging. Today s Topic. The Main Steps in Systematic Debugging

Correctness and Robustness

Assertions and Exceptions Lecture 11 Fall 2005

CSE 331 Software Design & Implementation

Administration. Exceptions. Leftovers. Agenda. When Things Go Wrong. Handling Errors. CS 99 Summer 2000 Michael Clarkson Lecture 11

Documen(ng code, Javadoc, Defensive Programming, Asserts, Excep(ons & Try/Catch

Software Engineering

CS 211 Programming Practicum Spring 2017

Written by John Bell for CS 342, Spring 2018

Comp 249 Programming Methodology Chapter 9 Exception Handling

Exceptions and Error Handling

Object Oriented Programming. Week 9 Part 1 File I/O

Good Coding Practices Spring 2018

Programming Assignment 4

What is the purpose of exceptions and exception handling? Vocabulary: throw/raise and catch/handle Exception propagation Java checked and unchecked

CS11 Java. Fall Lecture 4

References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 10/14/2004 1

Objectives for this class meeting. 1. Conduct review of core concepts concerning contracts and pre/post conditions

Exception Handling. Exception Handling

Basics of Java: Expressions & Statements. Nathaniel Osgood CMPT 858 February 15, 2011

About This Lecture. Outline. Handling Unusual Situations. Reacting to errors. Exceptions

Exceptions. Examples of code which shows the syntax and all that

Course Content. Objectives of Lecture 22 File Input/Output. Outline of Lecture 22. CMPUT 102: File Input/Output Dr. Osmar R.

Java Review Outline. basics exceptions variables arrays modulo operator if statements, booleans, comparisons loops: while and for

More on Objects in JAVA TM

Why Design by Contract! CS 619 Introduction to OO Design and Development. Design by Contract. Fall 2012

CS 251 Intermediate Programming Exceptions

7 The Integrated Debugger

9. Java Errors and Exceptions

23 Error Handling What happens when a method is called? 23.1 What is Exception Handling? A.m() B.n() C.p()

INTERNATIONAL EDITION. Problem Solving with C++ Data Abstraction & SIXTH EDITION. Walls and Mirrors. Frank M. Carrano Timothy Henry

Testing, Debugging, Program Verification

CMSC131. Exceptions and Exception Handling. When things go "wrong" in a program, what should happen.

CS115. Chapter 17 Exception Handling. Prof. Joe X. Zhou Department of Computer Science. To know what is exception and what is exception handling

Pages and 68 in [JN] conventions for using exceptions in Java. Chapter 8 in [EJ] guidelines for more effective use of exceptions.

CIS 110 Introduction to Computer Programming. February 29, 2012 Midterm

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 7

17. Handling Runtime Problems

Readability [Skrien 4.0] Programs must be written for people to read, and only incidentally for machines to execute.

1.00/ Introduction to Computers and Engineering Problem Solving. Final / December 13, 2004

Reminder. Topics CSE What Are Exceptions?! Lecture 11 Exception Handling

CSCI-142 Exam 2 Review September 25, 2016 Presented by the RIT Computer Science Community

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED

Transcription:

CS-152: Software Testing Neal Holtschulte July 2, 2013

Software Testing Outline Terminology Assertions and when to use them Try-catch and when to use them What are Exceptions Further resources Practice

Terminology Unit testing - testing small pieces of code (such as individual methods or functions). A collection of unit tests is known as a test suite. Regression testing is the process of repeatedly running tests. Source: Java An Introduction to Problem Solving and Programming by Savitch. Page 336.

Terminology A test case is an input output pair that we know to be correct. If we give our program (or a method of our program) the input and we do not get the expected output, then the program (or method) has failed the test case and we may have discovered a bug. Negative test - a test to make sure the system doesn t crash if given an unexpected input.

Tracing Tracing variables means watching the variables change value while the program is running. Often there are debugging utilities that will help you do this, but we re just going to use System.out.println.

Tracing Since we don t want all these print statements in the final version of our program we can use a p u b l i c s t a t i c f i n a l boolean DEBUG = t r u e ; Then you can wrap all your print statements in ifs and set DEBUG to false when you re done testing. i f ( DEBUG ){ System. out. println (" value s value is "+ value ); }

Assertions Assertions can be used to verify that certain conditions are true and make software more robust. / Get the largest integer value from myarray. / p u b l i c i n t getlargest ( i n t [] myarray ){ 5 //First check to make sure the array is //not empty. assert ( myarray. length > 0);...

Assertions Assertions can and should be used throughout your code to verify that any important conditions hold. Assertions provide a form of enforced documentation. Assertions help you find bugs faster. Assertions do not (usually) noticeably slow down software.

See TestingExample.java

Try-catch Try-catch statements can be used to throw more useful error messages or to make a program more robust by handling rare special cases. Java An Introduction to Problem Solving and Programming by Savitch. Chapter 9.

Try-catch p u b l i c Sandwhich makepbj (){ PeanutButter pb; t r y { pb = getpb (); 5 i f (pb. isempty ()){ throw new Exception (" EXCEPTION : No " + " Peanut Butter!"); } } catch ( Exception e){ 10 System. out. println (e. getmessage ()); System. out. println ("Go to the store and "+ " buy peanut butter."); }...

Try-catch Try-catch blocks are required around file readers because the file might not be found.

Try-catch t r y { //Create a new file reader and pass it the //file to read in. FileReader fr = new FileReader (" english.0"); 5 BufferedReader breader = new BufferedReader ( fr ); String line = breader. readline (); w h i l e ( line!= n u l l ){ text += line +","; line = breader. readline (); 10 } breader. close (); } catch ( Exception e){ System. out. println (" ERROR : There was a problem "+ 15 " reading the file.\n"+e. getmessage ()); System. exit (1); }

Try-catch Use a try-catch block whenever there is a special case that needs to be handled differently. Use a try-catch to trigger additional data-gathering when an exception occurs to help debug your code. For example:

Try-catch t r y { mystack. pop (); } catch ( Exception e){ 5 System. out. println (e. getmessage ()); mystack. printcontents (); System. exit (1); }

What are exceptions? An exception signals an unusual event during execution. Creating an exception is called throwing an exception. Code that deals with an exception is said to handle an exception. Java An Introduction to Problem Solving and Programming by Savitch. Page 659.

What are exceptions? Exceptions are objects that can be created and thrown throw new Exception (" EXCEPTION : No Peanut Butter!"); You can see what methods are available to be called on exceptions with Eclipse s autocomplete feature.

Testing advice Automated your testing process Make test output self-identifying Make tests reproducible Add a test for each bug Add tests for new features and changes Never throw away a test Further information about the above advice can be found here: http://www.cs.princeton.edu/~bwk/testing.html

Further resources Software Testing (free online course) https://www.udacity.com/course/cs258 Java Exceptions tutorial http://docs.oracle.com/javase/tutorial/essential/ exceptions/definition.html

Software Testing Outline Terminology Assertions and when to use them Try-catch and when to use it What are Exceptions Further resources Practice

Before we practice, Stacks

Let s... look at the stack code where might we insert assertions? what can go wrong? test the constructor discuss if negative arguments are reasonable use an assertion use a try-catch divide up and write tests for the buggy stack implementations

Let s... To Eclipse. code/stacktestingcode/