Testing and Debugging

Similar documents
Main concepts to be covered. Testing and Debugging. Code snippet of the day. Results. Testing Debugging Test automation Writing for maintainability

Introduc)on to tes)ng with JUnit. Workshop 3

Software Design Models, Tools & Processes. Lecture 6: Transition Phase Cecilia Mascolo

Verification and Validation

Week 1 Exercises. All cs121 exercise and homework programs must in the default package and use the class names as given.

Course Content. Objectives of Lecture 18 Black box testing and planned debugging. Outline of Lecture 18

New Concepts. Lab 7 Using Arrays, an Introduction

CMSC 132: OBJECT-ORIENTED PROGRAMMING II

Client-server application testing plan

Lecture 5: Methods CS2301

Benefits of object-orientationorientation

Chapter 11, Testing. Using UML, Patterns, and Java. Object-Oriented Software Engineering

Reliable programming

Test Driven Development TDD

Course: Honors AP Computer Science Instructor: Mr. Jason A. Townsend

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

Getting Started (1.8.7) 9/2/2009

Testing. Topics. Types of Testing. Types of Testing

Assertions. Assertions - Example

EXAMINING THE CODE. 1. Examining the Design and Code 2. Formal Review: 3. Coding Standards and Guidelines: 4. Generic Code Review Checklist:

Software Engineering

Software Engineering Testing and Debugging Testing

CS 520 Theory and Practice of Software Engineering Fall 2018

This guide will show you how to use Intel Inspector XE to identify and fix resource leak errors in your programs before they start causing problems.

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Repe$$on CSC 121 Fall 2015 Howard Rosenthal

Software LEIC/LETI. Lecture 5

Steps for project success. git status. Milestones. Deliverables. Homework 1 submitted Homework 2 will be posted October 26.

Testing. Prof. Clarkson Fall Today s music: Wrecking Ball by Miley Cyrus

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

Well-behaved Objects. Most of the chapter focuses on testing Our first project will involve a diary

Chapter 8. Achmad Benny Mutiara

ECE 3574: Applied Software Design: Unit Testing using Catch. Chris Wyatt

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

Implementation of Customized FindBugs Detectors

Unit Testing as Hypothesis Testing

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

APCS Semester #1 Final Exam Practice Problems

Unit Testing and Test Driven Design

Program development plan

From designing to coding

Introduction To Software Testing. Brian Nielsen. Center of Embedded Software Systems Aalborg University, Denmark CSS

2 Getting Started. Getting Started (v1.8.6) 3/5/2007

CSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too)

Web API Lab. The next two deliverables you shall write yourself.

Topics in Software Testing

Regression testing. Whenever you find a bug. Why is this a good idea?

Finding Firmware Defects Class T-18 Sean M. Beatty

CS 142 Style Guide Grading and Details

Starting to Program in C++ (Basics & I/O)

COMP 161 Lecture Notes 16 Analyzing Search and Sort

Softwaretechnik. Lecture 08: Testing and Debugging Overview. Peter Thiemann SS University of Freiburg, Germany

Equality for Abstract Data Types

RACKET BASICS, ORDER OF EVALUATION, RECURSION 1

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

Object Oriented Software Design - I

Softwaretechnik. Lecture 08: Testing and Debugging Overview. Peter Thiemann SS University of Freiburg, Germany

We first learn one useful option of gcc. Copy the following C source file to your

Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007

MEAP Edition Manning Early Access Program Get Programming with Java Version 1

CSSE 220. Interfaces and Polymorphism. Check out Interfaces from SVN

Repe$$on CSC 121 Spring 2017 Howard Rosenthal

11 Using JUnit with jgrasp

CSSE 220 Day 3. Check out UnitTesting and WordGames from SVN

AP Computer Science A Summer Assignment 2017

Verification and Validation

OBJECT INTERACTION. CITS1001 week 3

Verification and Validation

Last time. Reasoning about programs. Coming up. Project Final Presentations. This Thursday, Nov 30: 4 th in-class exercise

Reasoning about programs

Foundations of object orientation

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

Unit Testing as Hypothesis Testing

CMPSCI 187 / Spring 2015 Hanoi

Project 3 Due October 21, 2015, 11:59:59pm

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Lecture 15 Software Testing

ITEC 120 4/14/11. Review. Need. Objectives. GUI basics JFrame JPanel JLabel, JButton, JTextField Layout managers. Lecture 38 GUI Interactivity

PROGRAMMING FUNDAMENTALS

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

St. Edmund Preparatory High School Brooklyn, NY

Chapter 5 Errors. Hyunyoung Lee. Based on slides by Bjarne Stroustrup.

Errors. Lecture 6. Hartmut Kaiser hkaiser/fall_2011/csc1254.html

Programming Project 4: COOL Code Generation

Structured Programming

HOT-Compilation: Garbage Collection

Software Testing Interview Question and Answer

Program Correctness and Efficiency. Chapter 2

Laboratory 1: Eclipse and Karel the Robot

Chapter 15. Software Testing The assert Statement

C++ for Everyone, 2e, Cay Horstmann, Copyright 2012 John Wiley and Sons, Inc. All rights reserved. Using a Debugger WE5.

Testing is the process of evaluating a system or its component(s) with the intent to find whether it satisfies the specified requirements or not.

Jerry Cain Handout #5 CS 106AJ September 30, Using JSKarel

Under the Debug menu, there are two menu items for executing your code: the Start (F5) option and the

Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

Analysis of the Test Driven Development by Example

Introduction to Problem Solving and Programming in Python.

The compiler is spewing error messages.

Northeastern University - Seattle. Computer and Information Sciences

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

Transcription:

Testing and Debugging

(Reminder) Zuul Assignment Two deliverables: Code (to your submission folder by 23:59) Report (to your submission folder or hard copy to the CAS office by 4pm) Deadline is Tuesday, December 8, 2009

Code snippet of the day public void test () { int sum = 1; What is the output? for (int i = 0; i <= 4; i++); { sum = sum + 1; } System.out.println ("The result is: " + sum); System.out.println ("Double result: " + sum + sum); }

Code snippet of the day public void test () { int sum = 1; for (int i = 0; i <= 4; i++); { sum = sum + 1; } What is the output? This semi-colon marks the end of an empty statement, which is the loop body. System.out.println ("The result is: " + sum); System.out.println ("Double result: " + sum + sum); This code block follows the loop. With the semi-colon above, it is not the loop body. } The result is: 11562

Code snippet of the day public void test () { int sum = 1; What is the output? for (int i = 0; i <= 4; i++); { sum = sum + 1; } This arithmetic is never done the number is converted to a string and appended to the opening string (twice). System.out.println ("The result is: " + sum); System.out.println ("Double result: " + sum + sum); } The result is: 11562 Double result is: 422

We have to deal with errors Early errors are usually syntax errors: the compiler will spot these Later errors are usually logic errors: the compiler cannot help with these also known as bugs Some logical errors have intermittent manifestation with no obvious trigger: also known as bugs ****** Commercial software is rarely error free: often, it is much worse than this

Prevention vs Detection (Developer vs Maintainer) We can lessen the likelihood of errors: encapsulate data in fields of an object design each class to be responsible for one kind of thing We can improve the chances of detection: write documentation as we go think about how to test as we go test as we go (e.g. interact with classes/objects/methods using the facilities of BlueJ,, build a suite of testing classes see Unit Testing and Regression Testing in Chapter 6) We can develop detection skills.

Testing and Debugging These are crucial skills. Testing searches for the presence of errors. Debugging searches for the source of errors. the manifestation of an error may well occur some distance from its source.

Unit Testing Each unit of an application may be tested: each method each class each package Can (should) be done during development: finding and fixing early lowers development costs (e.g. programmer time). finding problems after deployment is very expensive. This is what usually happens. if the system design lacks cohesion and has high coupling between units, the bugs may never be found and, if found, be unfixable.

Testing Fundamentals Understand what the unit should do (its contract): look for violations (negative tests) look for fulfillment (positive tests) Test boundaries: for example, search an empty collection for example, add to a full collection

Unit Testing within BlueJ Objects of individual classes can be created. Individual methods can be invoked. Inspectors provide an up-to to-date view of an object s s state. Explore through the diary-prototype project (Chapter 6). This contains bugs!!!

Test Automation Good testing is a creative process. Thorough testing is time consuming and repetitive. Regression testing involves re-running running tests whenever anything is changed. Use of a test rig can relieve some of the burden: write classes to perform the testing creativity focused in creating these BlueJ offers help for this: explore the diary-testing project (Chapter 6). Human checking of the results still needed here. explore the diary-test-junit projects (Chapter 6). Machine checking of results human intervention only if one or more checks fail.

Debugging Techniques OK, we found errors how do we fix them? manual walkthoughs: read your code! why should it work? [Not:[ why doesn t t it work?!!] it helps to explain this to someone else if light has not dawned: add print statements to your code to show the state of variables (at key points) do they show what you expect? if light has not still not dawned: run your code under an interactive debugger BlueJBlueJ has support for this (see chapter 3.13)

Hofstadter's Law It always takes longer than you expect, even when you take Hofstadter's Law into account. 90% Rule of Project Schedules The first ninety percent of the task takes ninety percent of the time and the last ten percent takes the other ninety percent.

Modularisation in a Calculator Each module does not need to know implementation details of the other. User controls could be a GUI or a hardware device. Logic could be hardware or software.

Method Signatures as an Interface // Return the value to be displayed. public int getdisplayvalue(); // Call when a digit button is pressed. public void numberpressed(int number); // Call when a plus operator is pressed. public void plus(); // Call when a minus operator is pressed. public void minus(); // Call to complete a calculation. public void equals(); // Call to reset the calculator. public void clear();

Debugging It is important to develop codereading skills. Debugging will often be performed on others code. Techniques and tools exist to support the debugging process. Explore through the calculator-engine project.

Manual Walkthroughs Relatively underused. A low-tech approach. More powerful than appreciated. Get away from the computer! Run a program by hand. High-level (Step) or low-level level (Step into) views.

Tabulating Object State An object s behaviour usually depends on its state. Incorrect behaviour is often the result of incorrect state. Tabulate the values of all fields. Record state changes after each method call.

Verbal Walkthroughs Explain to someone else what the code is doing: explain why should it work! [don t t ask: why doesn t t it work?!!] the process of explaining helps you spot errors for yourself; often, it s easier for someone else! Group-based processes exist for conducting formal walkthroughs or inspections.

Print Statements The most popular technique. No special tools required. All programming languages support them. Only effective if the right methods are documented. Output may be voluminous! Turning off and on requires forethought.

Interactive Debuggers Debuggers are language-specific and environment-specific. BlueJ has an integrated debugger. Supports breakpoints. Provides step and step-into controlled execution. Shows the call sequence (stack). Shows object state. Does not provide a permanent record.

Review Errors are a fact of life in programs. Good software engineering techniques can reduce their occurrence. Testing and debugging skills are essential. Make testing a habit. Automate testing where possible. Practise a range of debugging skills.

Review Unit testing (with BlueJ) Chapter 6.3 Test automation (with BlueJ) Chapter 6.4 Manual walkthroughs (read the code!!!) Chapter 6.8 Print statements (see what s happening) Chapter 6.9 Debuggers (with BlueJ) Chapter 3.12-13, 6.11