Software Testing Lecture 1

Similar documents
Testing, Debugging, and Verification

Model Checking based Software Verification

Sources: On the Web: Slides will be available on:

Introduction to Python

CPSC 330 Software Engineering

Introduction to Automated Testing

Exploratory Testing in an Agile Context

Static vs. Dynamic Testing How Static Analysis and Run-Time Testing Can Work Together. Outline

Fail early, fail often, succeed sooner!

Unit Testing & JUnit

Approach of Unit testing with the help of JUnit

Chapter 8 Software Testing

The Course.

Test Driven Development

Introduction to Software Testing Chapter 8.1 Building Testing Tools Instrumentation. Chapter 8 Outline

CS4507 Advanced Software Engineering

Numerical Matrix Analysis

Software Testing. Theory and Practicalities

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

MXwendler Javascript Interface Description Version 2.3

Agile.NET Development Test-driven Development using NUnit

Introduction to Data Structures

Software Testing with Python

QA or the Highway 2016 Presentation Notes

Using EDA Databases: Milkyway & OpenAccess

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

JUnit. Introduction to Unit Testing in Java

Introduction to Computers and Programming. Testing

Software Testing. Quality & Testing. Software Testing

1 Description of The Simpletron

Rigorous Software Development CSCI-GA

Java course - IAG0040. Unit testing & Agile Software Development

Testgetriebene Entwicklung mit PHPUnit. PHP Professional Training 22 th of November 2007

Computer Science 217

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

Environment Modeling for Automated Testing of Cloud Applications

Tools, Trends and Techniques for Developing Scientific Software

Testing Mobile Apps CS 4720 Web & Mobile Systems

What s the status of testing? What are you doing today? When will you be finished? Why is it taking so long? Have you tested, yet?

Achieving business benefits through automated software testing. By Dr. Mike Bartley, Founder and CEO, TVS

Software Testing & Analysis (F22ST3): Static Analysis Techniques 2. Andrew Ireland

4. Test Design Techniques

Introduction to Python

Testing Methodology Assignment 1 Unit testing using JUnit

Intro to scientific programming (with Python) Pietro Berkes, Brandeis University

CSTE Mock Test - Part I - Questions Along with Answers

VHDL Test Bench Tutorial

Introduction to Software Testing Ammann & Offutt. Part I Overview

Unit Testing with zunit

1 White-Box Testing by Stubs and Drivers

Basic Testing Concepts and Terminology

Software Engineering. Top-Down Design. Bottom-Up Design. Software Process. Top-Down vs. Bottom-Up 13/02/2012

Unit Testing. and. JUnit

Capabilities of a Java Test Execution Framework by Erick Griffin

Cucumber: Finishing the Example. CSCI 5828: Foundations of Software Engineering Lecture 23 04/09/2012

Licensed for viewing only. Printing is prohibited. For hard copies, please purchase from

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

Advanced Software Testing

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

Python Programming: An Introduction to Computer Science

Requirements Based Testing Process Overview

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

Informatica e Sistemi in Tempo Reale

Software Engineering Techniques

Regression Verification: Status Report

Lazy OpenCV installation and use with Visual Studio

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Testing & Verification of Digital Circuits ECE/CS 5745/6745. Hardware Verification using Symbolic Computation

Java. Java. e=mc 2. composition

Using JUnit in SAP NetWeaver Developer Studio

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

An Incomplete C++ Primer. University of Wyoming MA 5310

Java Basics: Data Types, Variables, and Loops

Unit testing with JUnit and CPPUnit. Krzysztof Pietroszek

Course Goals. Solve Non-Technical Customer problem Server side: Ruby on Rails Client side: HTML, CSS, AJAX, JavaScript Deploy using cloud computing

Chemuturi Consultants Do it well or not at all Productivity for Software Estimators Murali Chemuturi

Benefits of Test Automation for Agile Testing

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Computer Systems Engineering: Spring Quiz I Solutions

ECS 165B: Database System Implementa6on Lecture 2

Continuous Integration

Stacks. Linear data structures

Programming in Access VBA

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

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Introduction to Java

Excel & Visual Basic for Applications (VBA)

CS101 Lecture 24: Thinking in Python: Input and Output Variables and Arithmetic. Aaron Stevens 28 March Overview/Questions

Unit Testing with FlexUnit. by John Mason

Welcome to Introduction to programming in Python

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Software Testing. Knowledge Base. Rajat Kumar Bal. Introduction

G10 Data Setting Command

Automated Software Testing by: Eli Janssen

Random Testing: The Best Coverage Technique - An Empirical Proof

An Introduction to text-based test automation and the TextTest tool

MANUAL USER GUIDE FOR EMR PRIMARY HEALTH CARE SYSTEM

How Safe does my Code Need to be? Shawn A. Prestridge, Senior Field Applications Engineer

Test Data Management Best Practice

Transcription:

Software Testing Lecture 1 Justin Pearson October 31, 2011 1 / 1

Four Questions Does my software work? 2 / 1

Four Questions Does my software work? Does my software meet its specification? 3 / 1

Four Questions Does my software work? Does my software meet its specification? I ve changed something does it still work? 4 / 1

Four Questions Does my software work? Does my software meet its specification? I ve changed something does it still work? How can I become a better programmer? 5 / 1

The Answer Testing 6 / 1

Software Failures NASA s Mars lander, September 1999, crashed due to a units integration fault cost over $50 million. The MCO MIB has determined that the root cause for the loss of the MCO spacecraft was the failure to use metric units in the coding of a ground software file, Small Forces, used in trajectory models. Specifically, thruster performance data in English units instead of metric units was used in the software application code titled SM FORCES (small forces). A file called Angular Momentum Desaturation (AMD) contained the output data from the SM FORCES software. The data in the AMD file was required to be in metric units per existing software interface documentation, and the trajectory modelers assumed the data was provided in metric units per the requirements. 1 1 ftp://ftp.hq.nasa.gov/pub/pao/reports/1999/mco report.pdf 7 / 1

Ariane 5 explosion Flight 501, which took place on Tuesday, June 4, 1996, was the first, and unsuccessful, test flight of the European Space Agency s Ariane 5 expendable launch system. Due to an error in the software design (inadequate protection from integer overflow), the rocket veered off its flight path 37 seconds after launch and was destroyed by its automated self-destruct system when high aerodynamic forces caused the core of the vehicle to disintegrate. It is one of the most infamous computer bugs in history. 8 / 1

Exception Handling t r y {...... } c a t ch ( A r i t h m e t i c O v e r f l o w ( ) ) {... S e l f D e s t r u c t.... } In fact it was an integration problem. The software module was for Ariane 4 and people forgot that Ariane 5 had higher initial acceleration. 9 / 1

Therac-25 Radiation therapy machine. At least 6 patients where given 100 times the intended dose of radiation. Causes are complex 2 but one cause identified: Inadequate Software Engineering Practices... including: The software should be subject to extensive testing and formal analysis at the module and software level; system testing alone is not adequate. Regression testing should be performed on all software changes. 2 http://sunnyday.mit.edu/papers/therac.pdf 10 / 1

Intel s fdiv bug Some pentiums returned instead of 4195835 3145727 = 1.333739068902037589 4195835 3145727 = 1.333820449136241002 11 / 1

Intel s fdiv bug With a goal to boost the execution of floating-point scalar code by 3 times and vector code by 5 times, compared to the 486DX chip, Intel decided to use the SRT algorithm that can generate two quotient bits per clock cycle, while the traditional 486 shift-and-subtract algorithm was generating only one quotient bit per cycle. This SRT algorithm uses a lookup table to calculate the intermidiate quotients necessary for floating-point division. Intel s lookup table consists of 1066 table entries, of which, due to a programming error, five were not downloaded into the programmable logic array (PLA). When any of these five cells is accessed by the floating point unit (FPU), it (the FPU) fetches zero instead of +2, which was supposed to be contained in the missing cells. This throws off the calculation and results in a less precise number than the correct answer(byte Magazine, March 1995). 12 / 1

Intel s fdiv bug Simple programming error, not getting your loop termination condition correct. Later we ll see that this might of been avoided with testing. 13 / 1

Software Failures These are just some of more spectacular examples. There is lots and lot of bad software out there. Anything we can do to improve the quality of software is a good thing. Formal methods are hard to implement, but software testing with some discipline can become part of any programmers toolbox. 14 / 1

Testing There are lots of different testing activities. We can t cover them all but they include: Unit Testing: Testing your functions/methods as you write your code. Regression testing: maintaining a possibly large set of test cases that have to passed when ever you make a new release. Integration testing: testing if your software modules fit together. As we learn about software engineering you ll see how different testing can be in different phases of the software engineering process. 15 / 1

Can we test? Program testing can be used to show the presence of bugs, but never to show their absence! Edsger Dijkstra. This is true, but it is no reason to give up on testing. All software has bugs. Anything you do to reduce the number of bugs is a good thing. 16 / 1

Test Driven Development Later on we will look at test driven development which is a programming discipline where you write the tests before you write the code. 17 / 1

What is a Test? A test is simply some inputs and some expected outputs. 18 / 1

Types of Testing 1. Test Design 2. Test Automation 3. Test Execution 4. Test Evaluation Very important test execution should be as automated as possible. It should be part of your Makefile. Some systems even automatically run tests when you check in code. 19 / 1

Test Design Writing good tests is hard. It requires knowledge of you problem. Knowledge of common errors. Often test designer is a separate position in a company. 20 / 1

Test Design Adversarial view of test design: How do I break software? 21 / 1

Test Design Adversarial view of test design: How do I break software? Constructive view of test design: How do I design software tests that improve the software process? 22 / 1

Test Automation Designing tests is hard. If you don t make running the tests an automated process then people will never run them. There are many automated systems, but you can roll your own via scripting languages. The xunit framework has support in most languages for the automated running of tests. It should be as simple as make tests. 23 / 1

Test Automation There are tools for automatically testing web systems. There are tools for testing GUIs. If you design you software correctly you should decouple as much of the GUI behaviour from the rest of the program as you can. This will not only make your program easier to port to other GUIs it will make it easier to test. Don t forget to include test automation in your make files. Consider integrating automated testing into your version management system. 24 / 1

Test Execution You need to think of test execution as separate activity. You have to remember to run the tests. In a large organization this might require some planning. Easy if testing is automated. Hard for some domains e.g. GUI. Can be hard in distributed or real time environments. 25 / 1

Test Evaluation My software does not pass some of the tests. Is this good or bad? My software passes all my tests. Can I go home now? Or do I have to design more tests? 26 / 1

Important Terminology Validation: The proess of evaluation software at the end of software development to ensure compliance with intended usage. Verification: The process of determining whether the products of a given phase of the software development process fulfill the requirements established during the previous phase 27 / 1

Important Terminology Software Fault: A static defect in the software Software Error: An incorrect internal state that is the manifestation of some fault Software Failure: External, incorrect behavior with respect to the requirements or other description of the expected behavior Understanding the difference will help you fix faults. Write your code so it is testable. 28 / 1

Pop Quiz How many times does this loop execute? f o r ( i =10; i <5; i ++) { d o s t u f f ( i ) ; } 29 / 1

Fault/Error/Failure Example i n t c o u n t s p a c e s ( char s t r ) { i n t l e n g t h, i, count ; count = 0 ; l e n g t h = s t r l e n ( s t r ) ; f o r ( i =1; i <l e n g t h ; i ++) { i f ( s t r [ i ] == ) { count++; } } return ( count ) ; } Software Fault: i=1 should be i=0. Software Error: some point in the program where you incorrectly count the number of spaces. Failure inputs and outputs that make the fault happen. For example count spaces("h H H"); would not cause the failure while count spaces(" H"); does. 30 / 1

Suggested Reading One of the testing gods is James Bach see his website 3 The book Introduction to Software Testing 4 by Ammann and Offutt. The book Test-Driven Development by Example by Kent Beck. Who is one of the fathers of unit testing, agile programming and extreme programming. 3 http://www.satisfice.com/ 4 http://cs.gmu.edu/ offutt/softwaretest/ 31 / 1

Unit Testing xunit testing is a framework where individual functions and methods are tested. It is not particularly well suited to integration testing or regression testing. The best way to write testable code is to write the tests as you develop the code. Writing the test cases after the fact takes more time and effort than writing the test during the code. It is like good documentation you ll always find something else to do if you leave until after you ve written the code. 32 / 1

The heart of Unit Testing The unit test framework is quite powerful. But the heart are two functions: asserttrue assertfalse 33 / 1

asserttrue Suppose we want to test our string length function int istrlen(char*) The the following things should be true: The length of "Hello" is 5. The length of "" is 0. The length of "My kingdom for a horse." is 23. 34 / 1

asserttrue Then we would assert that the following things are true: asserttrue (The length of "Hello" is 5.) asserttrue(the length of "" is 0.) asserttrue (The length of "My kingdom for a horse." is 23.) 35 / 1

asserttrue Key idea in xunit: asserttrue( executable code) Runs the executable code which should evaluate to true. assertfalse( executable code) Runs the executable code which should evaluate to false. 36 / 1

Different xunit frameworks run the tests in different ways. Python unit testing framework has a notion of test suites and registries. But it is quite simple to set up tests. Key to success in understanding complex APIs. Take example code and modify it to do what you want. 37 / 1

Python Unit Testing import c o d e t o b e t e s t e d import u n i t t e s t c l a s s TestCode ( u n i t t e s t. TestCase ) : def t e s t s ( s e l f ) : x = H e l l o s e l f. a s s e r t E q u a l ( l e n ( x ) == 5) 38 / 1

Important Unit Testing Concepts Setup. You might need to initialize some data structures. 39 / 1

Important Unit Testing Concepts Setup. You might need to initialize some data structures. The tests. Well you need to do tests. 40 / 1

Important Unit Testing Concepts Setup. You might need to initialize some data structures. The tests. Well you need to do tests. Teardown. Always clean up after you. 41 / 1

Important Unit Testing Concepts Setup. You might need to initialize some data structures. The tests. Well you need to do tests. Teardown. Always clean up after you. Important idea. Each test should be able to be run independently of the other tests. You don t know what order the tests will be run. Or even if all tests will be run. The programmer might just rerun the test that caused problems. 42 / 1

Teardown Teardown is more common in languages without automatic garbage collection. 43 / 1

More Testing Concepts Sometimes you don t have all the functionality implemented. Write dummy functions stubs that simply return null values rather doing any real work. Means that you can get your code going. Mock or Fake objects (people make a distinction but don t worry) implement enough of an object to get the test going. In fact in test driven development you write the test implement the mocks first and as you introduce more tests you add code to make the tests pass. 44 / 1

Test functions It is a matter of judgment and taste how many tests you put in each function. You don t want individual tests to take too much time to run. This will discourage the programmer from running individual test often. Whenever you compile your code you should run the tests. Often IDEs implement red and green bars for tests. Green means the test has passed and red means the test has failed. Green is good. 45 / 1

How to use Unit Tests When you are writing functions use test cases to see if the behaviour is as expected. Use tests as another form of documentation. Helps other programmers understand your API. When you find a bug write a test case and then correct the bug. Leave the test case there just in case fixing another bug reintroduces a bug. 46 / 1

Some things to test for Extreme values. Empty strings, large values. Loops executing zero, once, many times, and test the loop termination condition. f o r ( i n t i =0; i <M; i ++) { do something ( i ) ; } Find a test case that makes M be 0, 1 and some larger number. Often M will not be an input parameter. You might have to work out how the input parameters affect M v o i d whatever ( char s t r ) { M = s t r l e n ( s t r ) ;.... } So you have to have a string of length 0,1 and some bigger number. 47 / 1

Some things to test for Code coverage. This is a complex area, but you should not really have untested code. i f (X==Y) { do something ( ) ; } e l s e { d o s o m e t h i n g e l s e ( ) ; } Find a test case where X equals Y and a test case where they are different. 48 / 1

Have a reason You can t test code just by letting a monkey type random things on the keyboard (although it sometimes helps). Try to have a reason for every test. Document reasons. When you test suite gets too large you have to work out which tests to delete. 49 / 1