Software Testing.

Slides:



Advertisements
Similar presentations
Testing Relational Database
Advertisements

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.
Testing Coverage Test case
Test process essentials Riitta Viitamäki,
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
Software Architecture Prof.Dr.ir. F. Gielen
1 Basic Definitions: Testing What is software testing? Running a program In order to find faults a.k.a. defects a.k.a. errors a.k.a. flaws a.k.a. faults.
Working Software (Testing) Today’s Topic – Why testing? – Some basic definitions – Kinds of testing – Test-driven development – Code reviews (not testing)
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 23 Slide 1 Software testing.
Software Testing. Overview Definition of Software Testing Problems with Testing Benefits of Testing Effective Methods for Testing.
Software Testing. “Software and Cathedrals are much the same: First we build them, then we pray!!!” -Sam Redwine, Jr.
Testing Components in the Context of a System CMSC 737 Fall 2006 Sharath Srinivas.
Xtreme Programming. Software Life Cycle The activities that take place between the time software program is first conceived and the time it is finally.
Principle of Functional Verification Chapter 1~3 Presenter : Fu-Ching Yang.
1 Functional Testing Motivation Example Basic Methods Timing: 30 minutes.
What Exactly are the Techniques of Software Verification and Validation A Storehouse of Vast Knowledge on Software Testing.
Terms: Test (Case) vs. Test Suite
Software Testing Verification and validation planning Software inspections Software Inspection vs. Testing Automated static analysis Cleanroom software.
CS527: (Advanced) Topics in Software Engineering Overview of Software Quality Assurance Tao Xie ©D. Marinov, T. Xie.
System/Software Testing
Extreme Programming Software Development Written by Sanjay Kumar.
TESTING.
Objectives Understand the basic concepts and definitions relating to testing, like error, fault, failure, test case, test suite, test harness. Explore.
CS 501: Software Engineering Fall 1999 Lecture 16 Verification and Validation.
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
CS 360 Lecture 3.  The software process is a structured set of activities required to develop a software system.  Fundamental Assumption:  Good software.
Software Testing Testing principles. Testing Testing involves operation of a system or application under controlled conditions & evaluating the results.
Software Development Software Testing. Testing Definitions There are many tests going under various names. The following is a general list to get a feel.
Dr. Tom WayCSC Testing and Test-Driven Development CSC 4700 Software Engineering Based on Sommerville slides.
From Quality Control to Quality Assurance…and Beyond Alan Page Microsoft.
CSE403 Software Engineering Autumn 2001 More Testing Gary Kimura Lecture #10 October 22, 2001.
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
Software Testing Yonsei University 2 nd Semester, 2014 Woo-Cheol Kim.
16 October Reminder Types of Testing: Purpose  Functional testing  Usability testing  Conformance testing  Performance testing  Acceptance.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 22 Slide 1 Software Verification, Validation and Testing.
Software Construction Lecture 18 Software Testing.
Testing software Team Software Development Project.
(1) A beginners guide to testing Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu.
What is Testing? Testing is the process of finding errors in the system implementation. –The intent of testing is to find problems with the system.
Chapter 8 Lecture 1 Software Testing. Program testing Testing is intended to show that a program does what it is intended to do and to discover program.
Software Engineering 2004 Jyrki Nummenmaa 1 BACKGROUND There is no way to generally test programs exhaustively (that is, going through all execution.
CPSC 873 John D. McGregor Session 9 Testing Vocabulary.
Testing. Today’s Topics Why Testing? Basic Definitions Kinds of Testing Test-driven Development Code Reviews (not testing) 1.
Chapter 1: Fundamental of Testing Systems Testing & Evaluation (MNN1063)
Software Engineering1  Verification: The software should conform to its specification  Validation: The software should do what the user really requires.
1 Working Software (Testing) Today’s Topic Why testing? Some basic definitions Kinds of testing Test-driven development Code reviews (not testing) Today.
CPSC 871 John D. McGregor Module 8 Session 1 Testing.
Chapter 1 Software Engineering Principles. Problem analysis Requirements elicitation Software specification High- and low-level design Implementation.
Software Quality Assurance and Testing Fazal Rehman Shamil.
HNDIT23082 Lecture 09:Software Testing. Validations and Verification Validation and verification ( V & V ) is the name given to the checking and analysis.
Software Development Process CS 360 Lecture 3. Software Process The software process is a structured set of activities required to develop a software.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 23 Slide 1 Software testing.
Testing Overview Software Reliability Techniques Testing Concepts CEN 4010 Class 24 – 11/17.
Week # 4 Quality Assurance Software Quality Engineering 1.
Introduction to Software Testing Maili Markvardt.
Verification vs. Validation Verification: "Are we building the product right?" The software should conform to its specification.The software should conform.
1 Software Testing. 2 What is Software Testing ? Testing is a verification and validation activity that is performed by executing program code.
Software Testing and Quality Assurance Practical Considerations (1) 1.
CPSC 372 John D. McGregor Module 8 Session 1 Testing.
Introduction to Software Testing (2nd edition) Chapter 5 Criteria-Based Test Design Paul Ammann & Jeff Offutt
CSC 108H: Introduction to Computer Programming
Lecture 09:Software Testing
Testing and Test-Driven Development CSC 4700 Software Engineering
CS240: Advanced Programming Concepts
CSE 303 Concepts and Tools for Software Development
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
Working Software (Testing)
Software Testing “If you can’t test it, you can’t design it”
Software Testing.
Introduction to Software Testing
Presentation transcript:

Software Testing

Making Software Work Today's Topics Today is a look ahead to CS 362 Why testing? Some basic definitions Kinds of testing Test-driven development Code reviews (not testing) Today is a look ahead to CS 362 If you're already taking CS362, I apologize for the redundancy!

Why Testing? Ideally: we'd prove code correct, using formal mathematical techniques (with a computer, not chalk) Extremely difficult: for some trivial programs (100 lines) and many small (5K lines) programs Simply not practical to prove correctness in most cases – often not even for safety or mission critical code

Why Testing? Nearly ideally: use symbolic or abstract model checking to prove that a model is correct Automatically extract a mathematical abstraction from code Prove properties with model over all possible executions In practice, can work well for very simple properties ("this program never crashes in this particular way"), of some programs, but can't handle complex properties ("this is a working file system") Doesn't work well for programs with complex data structures (like a file system) Can't validate your requirements either!

As a last resort… … we can actually run the program, to see if it works This is software testing Always necessary, even when you can prove correctness – because the proof is seldom directly tied to the actual code that runs "Beware of bugs in the above code; I have only proved it correct, not tried it" – Knuth

NOT a last resort… Testing is a critical part of every software development effort Can too easily be left as an afterthought, after it is expensive to correct faults and when deadlines are pressing The more code that has been written when a fault is detected, the more code that may need to be changed to fix the fault Consider a key design flaw: better to detect with a small prototype, or after implementation is "finished"? May "have to ship" the code even though it has fatal flaws

Testing and Reviews in Processes Waterfall Requirements analysis Prototyping Design Implementation Testing Operation

Testing and Reviews in Processes Spiral Draft a menu of program designs Analyze risk & prototype Draft a menu of architecture designs Analyze risk & prototype Draft a menu of requirements Analyze risk & prototype Establish requirements Plan Establish architecture Plan Establish program design Operation Testing Implementation

Testing and Reviews in Processes Agile Do "spike" to evaluate & control risk Customer provides "stories" (short requirement snippets) Prioritize stories and plan Write/run/modify unit tests Operation Implement System and acceptance tests

Testing saves lives and money NIST report, "The Economic Impacts of Inadequate Infrastructure for Software Testing" (2002) Inadequate software testing costs the US alone between $22 and $59 billion annually Better approaches could cut this amount in half Major failures: Ariane 5 explosion, Mars Polar Lander, Intel's Pentium FDIV bug Insufficient testing of safety-critical software can cost lives: THERAC-25 radiation machine: 3 dead We want our programs to be reliable Testing is how, in most cases, we find out if they are Ariane 5: exception-handling bug : forced self destruct on maiden flight (64-bit to 16-bit conversion: about 370 million $ lost) Mars Polar Lander crash site? THERAC-25 design

Testing is as Glorious as Development Testing used to be thought as of grunt work With the advent of unit testing, regression testing, automated testing, and the necessary “closeness” between requirements and testing… Testing is no longer just grunt work You need the same technical skills and abilities as developers do

Today's Topic Why testing? Some basic definitions Kinds of testing Test-driven development Code reviews (not testing)

Basic Definitions: Testing What is software testing? Running a program Generally, in order to find faults (bugs) Could be in the code Or in the spec Or in the documentation Or in the test case…

Terms: Test case vs. Test Suite Test case (or test): one execution of the program, that may expose a bug Test suite: a set of executions of a program, grouped together A test suite is made of test cases Tester: a program (or a person!) that generates tests

Terms: Coverage Coverage measures or metrics Abstraction of "what a test suite tests" in a structural sense Common measures: Statement coverage a.k.a line coverage or basic block coverage Ideally, all of the test cases covers every line of code Decision coverage Which boolean expressions in control structures evaluated to both true and false during suite execution Path coverage Which paths through a program's control flow graph are taken in the test suite Ideally, every branch in the code is covered! Mutation coverage Ability to detect random variations to the code

Today's Topic Why testing? Some basic definitions Kinds of testing Test-driven development Code reviews (not testing)

Kinds of testing Whitebox Blackbox Unit Integration System Acceptance Regression (These aren’t mutually exclusive!)

Terms: Black Box Testing Treats a program or system as a That is, testing that does not look at source code or internal structure of the system Send a program a stream of inputs, observe the outputs, decide if the system passed or failed the test Abstracts away the internals – a useful perspective for integration and system testing Sometimes you don't have access to source code, and can make little use of object code True black box? Access only over a network

Terms: White Box Testing Opens up the box! (also known as glass box, clear box, or structural testing) Use source code (or other structure beyond the input/output spec.) to design test cases

Stages of Testing Unit testing is the first phase, done by developers of modules Integration testing combines unit-tested modules and tests how they interact System testing tests a whole program to make sure it meets requirements Acceptance testing by users to see if system meets actual use requirements

Stages of Testing: Unit Testing Unit testing is the first phase, mostly done by developers of modules Typically the earliest type of testing done Unit could be as small as a single function or method Often relies on stubs to represent other modules and incomplete code Unit testing tools are available for most popular languages, for example: JUnit (http://junit.org) Simpletest for PHP (http://simpletest.org) YUI test for Javascript (http://yuilibrary.com/projects/yuitest/) Python and Ruby have unit testing built into their language packages

Stages of Testing: Integration Testing Integration testing combines unit-tested modules and tests how they interact Relies on having completed units After unit testing, before system testing Test cases focus on interfaces between components, and assemblies of multiple components Often more formal (test plan presentations) than unit testing

Stages of Testing: System Testing System testing tests a whole program to make sure it meets requirements After integration testing Focuses on "breaking the system" Defects in the completed product, not just in how components interact Checks quality of requirements as well as the system Often includes stress testing, goes beyond bounds of well-defined behavior

An aspect of System Testing: Functional Testing Functional testing is when a developer tests a program from a "user's" perspective – does it do what it should? It's a different mindset than unit testing, which often proceeds from the perspective of other parts of the program Module spec/interface, not user interaction Sort of a fuzzy line – consider a file system – how different is the use by a program and use of UNIX commands at a prompt by a user? Building inspector does "unit testing"; you (or user), walking through the house to see if its livable, perform "functional testing" Kick the tires vs. take it for a spin?

Stages of Testing: Acceptance Testing Acceptance testing by users to see if system meets actual use requirements Black box testing By end-users to determine if the system produced really meets their needs May revise requirements/goals as much as find bugs in the code/system

Appropriate at all times: Regression Testing Changes can break code, reintroduce old bugs Things that used to work may stop working (e.g., because of another "fix") – software regresses Usually a set of cases that have failed (& then succeeded) in the past Finding small regressions is an ongoing research area – analyze dependencies ". . . as a consequence of the introduction of new bugs, program maintenance requires far more system testing. . . . Theoretically, after each fix one must run the entire batch of test cases previously run against the system, to ensure that it has not been damaged in an obscure way. In practice, such regression testing must indeed approximate this theoretical idea, and it is very costly." - Brooks, The Mythical Man-Month

Today's Topic Why testing? Some basic definitions Kinds of testing Test-driven development Code reviews (not testing)

Test-Driven Development One way to make sure code is tested as early as possible is to write test cases before the code Idea arising from Extreme Programming and often used in agile development Write (automated) test cases first Then write the code to satisfy tests

Test-Driven Development How to add a feature to a program, in test-driven development Add a test case that fails, but would succeed with the new feature implemented As a corollary, your interfaces, inputs, and outputs need to be well-defined! Run all tests, make sure only the new test fails Write code to implement the new feature Rerun all tests, making sure the new test succeeds (and no others break)

Test-Driven Development Cycle

Example 1: What should I test ? Consider this method (in Python): What would you test? #!/usr/bin/python … def readfile(gamesfile): fh = open(gamesfile, "r”) print "Games released in 2013:" for line in fh: record = line.split(",") if record[2] == '2013\n': print record[1] fh.close() Data in file: 0,Retrovirus,2013 1,Bastion,2011 2,VVVVVV,2010 gamesfile with empty string gamesfile that doesn’t exist on disk The data in gamesfile: A file with Windows style linefeeds vs. Unix Records with too many commas Records with not enough commas Below is sample data that would mess up the output. 0,Retrovirus,2013 1,Bastion,2011 2,VVVVVV,2010 3,FTL,2012 4,Starbase Orion,2011 5,Super Meat Boy,2010 6,Aquaria,2007 7,10,000,000,2013 8,Ball of Woe,2013

Example 2: What should I test? Consider this method (in Javascript): What would you test? function feet_to_inches(input) { var inches = 0; var matchResult = input.match(/(\d+)'\s*(\d*)"/i); if (typeof matchResult[1] !== 'undefined') { inches += parseInt(matchResult[1]) * 12; } if (typeof matchResult[2] !== 'undefined') { inches += parseInt(matchResult[2]); return inches; 5’6” 5’ 6” 5 6” 7” 5’ 5’6 15’ 12113” Regular expressions: \d: a digit +: at least one previous character ‘: match the quote \s: whitespace *: 0 or more previous characters “: match the double-quote Parentheses are placed into matchResults[0] and matchResults[1]

Test-Driven Development Benefits Results in lots of useful test cases A very large regression set Forces attention to actual behavior of software: observable & controllable behavior Only write code as needed to pass tests And may get good coverage of paths through the program, since they are written in order to pass the tests Reduces temptation to tailor tests to idiosyncratic behaviors of implementation Testing is a first-class activity in this kind of development

Test-Driven Development Problems Need institutional support Difficult to integrate with a waterfall development Management may wonder why so much time is spent writing tests, not code Lots of test cases may create false confidence If developers have written all tests, may be blind spots due to false assumptions made in coding and in testing, which are tightly coupled Can be a poor use of time If you aren’t exactly sure what modules or data structures you need, you might spend a lot of time modifying tests instead of doing it right the first time

Exhaustive vs. Representative Testing Can we test everything? File system is a library, called by other components of some flight software Operation Result mkdir ("/eng", …) SUCCESS mkdir ("/data", …) SUCCESS creat ("/data/image01", …) SUCCESS creat ("/eng/fsw/code", …) ENOENT mkdir ("/data/telemetry", …) SUCCESS unlink ("/data/image01") SUCCESS File system / /eng /data image01 /telemetry

Example: File System Testing How hard would it be to just try "all" the possibilities? Consider only core 7 operations (mkdir, rmdir, creat, open, close, read, write) Most of these take either a file name or a numeric argument, or both Even for a "reasonable" (but not provably safe) limitation of the parameters, there are 26610 executions of length 10 to try Not a realistic possibility (unless we have 1012 years to test)

Today's Topic Why testing? Some basic definitions Kinds of testing Test-driven development Code Reviews (not testing)

Not Testing: Code Reviews Not exactly testing, but an important method for finding bugs and determining the quality of code Code walkthrough: developer leads a review team through code Informal, focus on code Code inspection: review team checks against a list of concerns Team members prepare in advance in many cases Team moderator usually leads

Not Testing: Code Reviews Code inspections have been found to be one of the most effective practices for finding faults Some experiments show removal of 67-85% of defects via inspections Some consider XP's pair programming as a kind of "code review" process, but it's not quite the same Why? Can review/walkthrough requirements and design documents, not just code!