Outline. 1 Denitions. 2 Principles. 4 Implementation and Evaluation. 5 Debugging. 6 References



Similar documents
Software testing. Objectives

Chapter 1: Key Concepts of Programming and Software Engineering

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

Software Engineering Techniques

Logistics. Software Testing. Logistics. Logistics. Plan for this week. Before we begin. Project. Final exam. Questions?

Software development process

Loop Invariants and Binary Search

Module 2. Software Life Cycle Model. Version 2 CSE IIT, Kharagpur

Unit Testing & JUnit

Chapter 8 Software Testing

How To Improve Software Quality

(Refer Slide Time: 01:52)

Integrated Error-Detection Techniques: Find More Bugs in Java Applications

Software Engineering. How does software fail? Terminology CS / COE 1530

Benefits of Test Automation for Agile Testing

Basic Testing Concepts and Terminology

APPROACHES TO SOFTWARE TESTING PROGRAM VERIFICATION AND VALIDATION

Software Testing. Quality & Testing. Software Testing

Outline. Computer Science 331. Stack ADT. Definition of a Stack ADT. Stacks. Parenthesis Matching. Mike Jacobson

Testing and Inspecting to Ensure High Quality

CS 451 Software Engineering Winter 2009

Lockout/Tagout (LOTO): Automating the process

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.

Test-Driven Development

Software Engineering I: Software Technology WS 2008/09. Integration Testing and System Testing

VDM vs. Programming Language Extensions or their Integration

Introduction to Computers and Programming. Testing

Good FORTRAN Programs

Chapter 11, Testing, Part 2: Integration and System Testing

How To Develop Software

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Approach of Unit testing with the help of JUnit

Experiences with Online Programming Examinations

Lecture 9 - Message Authentication Codes

Testing, Debugging, and Verification

THE THREE ASPECTS OF SOFTWARE QUALITY: FUNCTIONAL, STRUCTURAL, AND PROCESS

Testing Tools Content (Manual with Selenium) Levels of Testing

Module 10. Coding and Testing. Version 2 CSE IIT, Kharagpur

Software Engineering Introduction & Background. Complaints. General Problems. Department of Computer Science Kent State University

Capabilities of a Java Test Execution Framework by Erick Griffin

Functional and LoadTest Strategies

Computer Programming I

Secrets to Automation Success. A White Paper by Paul Merrill, Consultant and Trainer at Beaufort Fairmont, LLC

CSCI E 98: Managed Environments for the Execution of Programs

The Trip Scheduling Problem

Testing, What is it Good For? Absolutely Everything!

WESTMORELAND COUNTY PUBLIC SCHOOLS Integrated Instructional Pacing Guide and Checklist Computer Math

Evaluation of AgitarOne

Lecture Notes on Linear Search

A framework for creating custom rules for static analysis tools

Testing Rails. by Josh Steiner. thoughtbot

Regression Verification: Status Report

National University of Ireland, Maynooth MAYNOOTH, CO. KILDARE, IRELAND. Testing Guidelines for Student Projects

Digital Systems. Role of the Digital Engineer

co Characterizing and Tracing Packet Floods Using Cisco R

Software Engineering Concepts: Testing. Pointers & Dynamic Allocation. CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009

An introduction to marketing for the small business

Crowdsourced Code Review in Programming Classes

Free Report: How To Repair Your Credit

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

Testability of Dependency injection

CSC408H Lecture Notes

What Is Specific in Load Testing?

PL/SQL Practicum #2: Assertions, Exceptions and Module Stability

Upping the game. Improving your software development process

PHP Debugging. Draft: March 19, Christopher Vickery

Waterfall vs. Agile Methodology

Latest Research and Development on Software Testing Techniques and Tools

Getting started with API testing

SMART PREPARATION FOR DATA CENTER MIGRATION

vector vec double # in # cl in ude <s ude tdexcept> tdexcept> // std::ou std t_of ::ou _range t_of class class V Vector { ector {

Monitoring, Tracing, Debugging (Under Construction)

Formal Software Testing. Terri Grenda, CSTE IV&V Testing Solutions, LLC

4.1 Introduction - Online Learning Model

Ten questions to ask when evaluating SAP change management solutions

Lecture 12: Software protection techniques. Software piracy protection Protection against reverse engineering of software

Module 1. Introduction to Software Engineering. Version 2 CSE IIT, Kharagpur

White Paper Business Process Modeling and Simulation

Notes on Factoring. MA 206 Kurt Bryan

Testing. Chapter. A Fresh Graduate s Guide to Software Development Tools and Technologies. CHAPTER AUTHORS Michael Atmadja Zhang Shuai Richard

Software Requirements Specification of A University Class Scheduler

Project Development & Software Design

Tools for Integration Testing

Topology-based network security

54 Robinson 3 THE DIFFICULTIES OF VALIDATION

G53QAT COURSEWORK BY ADEOLU OPEOLUWA OPEODU AXO16U. Test Planning

Software Engineering for LabVIEW Applications. Elijah Kerry LabVIEW Product Manager

Software Engineering. Software Testing. Based on Software Engineering, 7 th Edition by Ian Sommerville

Adversary Modelling 1

Automated Testing Options for PL/SQL Steven Feuerstein PL/SQL Evangelist, Quest Software

Best Practices for Threat & Vulnerability Management. Don t let vulnerabilities monopolize your organization.

And the Models Are System/Software Development Life Cycle. Why Life Cycle Approach for Software?

Testing Overview and Black-Box Testing Techniques

Transcription:

Outline Computer Science 331 Introduction to Testing of Programs Mike Jacobson Department of Computer Science University of Calgary Lecture #3-4 1 Denitions 2 3 4 Implementation and Evaluation 5 Debugging 6 References Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 1 / 30 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 2 / 30 What is Testing? Denitions Well-Designed Test Plans Denitions Testing: is the process of examining or running a program in order to nd errors. provides some evidence that software meets its specications Four main characteristics of well-designed test plans: A Test Plan (or \Testing Strategy"): : : is a systematic approach to testing software includes deciding how software will be tested deciding when tests will occur deciding who will do the testing deciding what test data will be used and what the expected output should be for each input Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 3 / 30 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 4 / 30

Denitions Denitions What is Defensive Programming? What is Debugging? Defensive Programming: : : See is a style of programming intended to ensure that software continues to function (or, at least, does not cause harm) in spite of unforeseeable use of the software includes the use of code that detects unexpected or invalid input data values one way of \preparing for testing" as you write your code http://en.wikipedia.org/wiki/defensive programming for more information about defensive programming. One advantage of developing a test plan early is that it makes defensive programming easier. Debugging is a methodical process of nding and removing defects in a program. General process: Recognize that a bug exists (eg. ideally, via testing) Isolate the source of the bug Identify the cause of the bug Determine a x for the bug Apply the x and test it A Common Error in Debugging: Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 5 / 30 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 6 / 30 Is This the Objective of Testing? More About the Objective of Testing Assumming that we are testing complex software including an extremely large number of lines of code Q: Do we test in order to prove that a program is correct? A: No! Explanation: Objective of Testing: We test in order to prove that a program is incorrect! Explanation: It is extremely unlikely that long and complex software is free of errors It is generally cheaper and easier to correct an error if it is detected early in software development Adversarial mindset (goal is to try to make the program fail) improves chances of locating errors Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 7 / 30 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 8 / 30

Who Should Test Your Software? A Limitation of Testing It is frequently a good idea to have someone else test the software you have designed and implemented (if possible!). Explanation: We all have \blind spots:" Frequently, other people can more easily see problems with our work that we don't notice ourselves It is easy (and human) for us to be overly \protective" of our own work we'd like to think it is perfect! This is is not helpful, considering that \the goal of testing is to prove that your software is incorrect" You cannot use testing to improve software quality, ie, readability complexity maintainability eciency Q: When do we try to achieve these desirable properties? A: Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 9 / 30 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 10 / 30 Why Prove Correctness and Test? We need to prove correctness (or, at least, know about a proof of correctness) because... you can't \test in" quality or use testing to repair a method based on an incorrect algorithm or debug code eectively unless you know what it is supposed to do We need to test because... proofs of correctness tend to be \sketched" instead of developed in detail, or skipped altogether, if correctness seems \obvious" sometimes the proofs are faulty... and they tend to rely on idealistic and unrealistic assumptions (e.g.: arithmetic is exact); testing provides a \reality check" a variety of errors can be introduced during the coding phase, even if you are starting with an algorithm that really is \correct." of Testing Remember what kind of software we are testing (large, complex)! Summary: A test succeeds if it nds an error. It is (almost always) impossible to test completely. Development of a test plan can and should begin early on in software development. Ideally, you should not test your own program. Testing can be eective in detecting and removing (some) errors from well-designed software. It is generally not eective if used to improve low-quality software. If you nd lots of errors, there are probably lots more! Testing takes time and hard work but is worth it! Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 11 / 30 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 12 / 30

Unit Testing Integration Testing During Unit Testing : : : each \module" (class or function) is tested individually. goal is to show that each module meets its specications ignores interaction between modules This is the rst stage of software testing later stages consider groups of modules, and are simpler if we can be condent that each module works correctly by itself Well-written unit tests serve as important documentation describes the expected behaviour of the module on a variety of inputs (ideally including both \valid" and \invalid" inputs) Integration Testing : : : is performed after unit testing. Individual modules (that separately seem to be acceptable) are combined to form and test progressively larger subsystems. Multiple methods of an object might be tested in combination as part of this process. Overall idea \building block" approach gradually add and test new modules to a tested base after testing the integration of a new module, it is added to the tested base and the process is repeated with a new module, until all have been included Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 13 / 30 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 14 / 30 Regression Testing Validation Testing Regression Testing: If an error is found and corrected then testing of the aected modules and subsystems should be repeated, to be sure no new errors were introduced! This is one reason why it is important to document tests you may need to use them more than once! Note: bugs can also be reintroduced via: poor revision control practices (eg. when two people work on the same code) inadequate documentation of testing (so that, eg., bug #1 gets reintroduced when recoding to eliminate bug #3) Validation (Acceptance) Testing : : : is performed after integration testing. Previous testing is generally conducted by software developers (possibly including testing specialists). Validation testing also involves potential users of the software (or current users, if an existing system is being changed or replaced). Idea is to test completed program using test cases and environments as close to (and as extreme as) input from actual users. This type of testing is beyond the scope of CPSC 331. Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 15 / 30 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 16 / 30

System Testing System Testing : : : is performed after validation testing (if it is needed). Used when the software being developed is part of a large system with other components (possibly including other software as well as specialized hardware, people, etc... ). This larger system is tested. Analogous to integration testing, where the \module" to be integrated into a larger system is the entire software system (now being integrated into a system with other kinds of components) This type of testing is also beyond the scope of CPSC 331. Static Testing Static Testing (structured walkthrough): involves examination of source code without execution. often rst stage of unit testing is a \reality-check" on code before proceeding to more detailed or complicated testing Two types: Desk checking: read through code, look for errors Hand Executions: trace code execution on small inputs with known outputs by hand Support Tools: pencil, paper, time, patience, : : : Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 17 / 30 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 18 / 30 Dynamic Testing Black Box Testing Dynamic Testing: tests the behaviour of a module or program during execution. Two types: Black Box Testing (also called Functional Testing) White Box Testing (also called Structural Testing) Both black box and white box testing are useful for all phases of testing Black Box Testing : : : includes tests designed using only the problem specication (not the code) tests both valid and invalid input tests typical cases and boundary conditions (special, rarely-occurring cases) is useful for nding incorrect or missing functions, interface errors (involving functions), interface errors for data structures or external data bases, initialization and termination errors. is generally used in later testing states, but certainly can and should be used during unit testing too. Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 19 / 30 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 20 / 30

Example Example Test Cases Consider an object's method with the following signature: Example test case inputs for x.removeme(): and with public void removeme ( Object[] array ); Pre-Condition: input array is not null Post-Condition: input has been modied by a removal of the rst instance of this, closing the gap and setting the last entry of the input to null, if this was found as an array entry; otherwise, the input is unchanged and a NoSuchElementException is thrown Exceptions: NoSuchElementException NullPointerException Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 21 / 30 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 22 / 30 White Box Testing Why White Box Testing is Useful Includes tests designed using the internal workings of a module (including source code). goal is to test every line of code and every execution path Tests typically try to ensure that: every statement in code is executed in one or more tests each \if" and \else" branch of every conditional statement is tested each loop is iterated zero, one, several, and as many times as possible (if these situations are feasible) each exit condition causing a loop or function to terminate is executed all exception handling is tested Use white box testing to test paths not covered by black box tests: parts of code (unit testing) paths/interfaces between units (integration testing) interactions between systems (system testing) Two reasons why this is useful (may be more!): 1 2 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 23 / 30 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 24 / 30

Implementation and Evaluation Important Note About Test Design Implementation and Evaluation Additional Code for Unit and Integration Testing Tests must be designed completely before tests are carried out. In particular, a test's expected results must be determined and documented, so that they are available for comparison with the values that are actually generated when a test is carried out. The design and executation of tests can begin before coding and be carried out during and after coding: Black box tests can be designed using specications of requirements before coding begins. Unit tests can be executed once individual modules are completed (and before others have). Integration tests can be carried out gradually, while coding continues, as well. Stub: piece of code that simulates the activity of a missing component (that is called by whatever you are testing) could be simple as something that echoes the input it receives and prompts for, and returns, appropriate data to the module being tested could be as complex as an alternate (perhaps, resource-inecient) fully functional implementation of another part of the system Driver: piece of code that emulates a calling function (supplying test data to whatever you are testing and reporting test results) Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 25 / 30 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 26 / 30 Test Harness Implementation and Evaluation Implementation and Evaluation Write Your Code to Make Testing Easier Test Harness: combination of a software test engine and a test data repository automates testings (running tests and monitoring results) since it will often be necessary to repeat tests the overhead associated with the use of this is generally worthwhile! Note: You will be using a test harness (including the test engine JUnit) in this course. This is part of \defensive programming." Document your code appropriately! Include preconditions and postconditions for methods, including in javadoc comments for all public methods Include loop invariants and loop variants for loops Include assertions describing expected program state at critical code segments Two helpful mechanisms provided by Java: Exceptions discussed in Section 2.3 of the text Assertions information available on the course web site Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 27 / 30 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 28 / 30

Debugging References Advice for Debugging Further Reading Recommended Steps: Reproduce the error (what inputs and execution environments cause the error?) Simplify the error (use the simplest possible input that causes the error when debugging) Locate the error (divide and conquer isolate class, then function, code block,...) Know what the program should do (compare against what the program does do) Look at all details (keep an open mind!) Make sure you understand the bug before you \x" it (no quick-xes to make the particular input work) Chapter 2 of the Koman and Wolfgang reference has additional information including a JUnit case study/tutorial Wikipedia has an extensive series of helpful articles on software testing as well as debugging. Sun's documentation on programming with assertions in Java including the assert class (see course web page for URL) Self-study and lab exercises on the course web page. Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 29 / 30 Mike Jacobson (University of Calgary) Computer Science 331 Lecture #3-4 30 / 30