Hao Zhong Shanghai Jiao Tong University

Slides:



Advertisements
Similar presentations
Object Oriented Analysis And Design-IT0207 iiI Semester
Advertisements

Test Yaodong Bi.
Test process essentials Riitta Viitamäki,
J-Unit Framework.
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
Testing and Debugging CS221 – 2/13/09. Airline Program.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 23 Slide 1 Software testing.
SE 450 Software Processes & Product Metrics Reliability: An Introduction.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
Software Testing. “Software and Cathedrals are much the same: First we build them, then we pray!!!” -Sam Redwine, Jr.
CS4723 Software Validation and Quality Assurance Lecture 02 Overview of Software Testing.
Swami NatarajanJuly 14, 2015 RIT Software Engineering Reliability: Introduction.
CS 3773 Software Engineering Basic Concepts of Software Testing Unit Testing.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 23 Slide 1 Software testing.
CS5103 Software Engineering Lecture 13 Software Licenses Software Testing.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
Software Testing Verification and validation planning Software inspections Software Inspection vs. Testing Automated static analysis Cleanroom software.
System/Software Testing
Lecture 6 Software Testing and jUnit CS140 Dick Steflik.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
CMSC 345 Fall 2000 Unit Testing. The testing process.
Chapter 8 – Software Testing Lecture 1 1Chapter 8 Software testing The bearing of a child takes nine months, no matter how many women are assigned. Many.
CS5103 Software Engineering Lecture 15 System Testing Testing Coverage.
INT-Evry (Masters IT– Soft Eng)IntegrationTesting.1 (OO) Integration Testing What: Integration testing is a phase of software testing in which.
Testing Workflow In the Unified Process and Agile/Scrum processes.
Dr. Tom WayCSC Testing and Test-Driven Development CSC 4700 Software Engineering Based on Sommerville slides.
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
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.
1 Introduction to Software Testing. Reading Assignment P. Ammann and J. Offutt “Introduction to Software Testing” ◦ Chapter 1 2.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
Software Engineering1  Verification: The software should conform to its specification  Validation: The software should do what the user really requires.
CPSC 871 John D. McGregor Module 8 Session 1 Testing.
©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.
Software Testing Reference: Software Engineering, Ian Sommerville, 6 th edition, Chapter 20.
Verification vs. Validation Verification: "Are we building the product right?" The software should conform to its specification.The software should conform.
Laurea Triennale in Informatica – Corso di Ingegneria del Software I – A.A. 2006/2007 Andrea Polini XVIII. Software Testing.
Software Testing. Software Quality Assurance Overarching term Time consuming (40% to 90% of dev effort) Includes –Verification: Building the product right,
Software Testing.
SOFTWARE TESTING Date: 29-Dec-2016 By: Ram Karthick.
Software Engineering (CSI 321)
Integration Testing.
Software Testing.
John D. McGregor Session 9 Testing Vocabulary
Chapter 9, Testing.
Test Automation CS 4501 / 6501 Software Testing
Architecture Concept Documents
CompSci 230 Software Construction
Chapter 8 – Software Testing
CS5123 Software Validation and Quality Assurance
Some Simple Definitions for Testing
Chapter 13 & 14 Software Testing Strategies and Techniques
Mid-term Exam Account for 20% of the grade 100 points in total
John D. McGregor Session 9 Testing Vocabulary
John D. McGregor Session 9 Testing Vocabulary
Software testing strategies 2
Introduction to Software Testing
Lecture 09:Software Testing
Higher-Level Testing and Integration Testing
Testing and Test-Driven Development CSC 4700 Software Engineering
Software testing.
CS240: Advanced Programming Concepts
Chapter 10 – Software Testing
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
CSE403 Software Engineering Autumn 2000 More Testing
Software Testing “If you can’t test it, you can’t design it”
Chapter 11: Integration- and System Testing
Software Testing.
Chapter 13 & 14 Software Testing Strategies and Techniques 1 Software Engineering: A Practitioner’s Approach, 6th edition by Roger S. Pressman.
Presentation transcript:

Hao Zhong Shanghai Jiao Tong University Quality engineer Hao Zhong Shanghai Jiao Tong University

Last class Programmer Code style Design pattern How to program with others Code style variable, …, class Design pattern Good vs Evil

Role A software quality analyst is responsible for applying the principles and practices of software quality assurance throughout the software development life cycle. A software bug is an error, flaw, failure or fault in a computer program or system that causes it to produce an incorrect or unexpected result, or to behave in unintended ways.

Software bug Errors can happen in any engineering discipline Software is one of the most error-prone products of all engineering areas Software can be really complex, undecidable problems are everywhere Most product are put into the market with no or very few errors Mars Climate Orbiter ($165M, 1998) Smashed to the planet: failing to convert between English measure to metric values Shooting down of Airbus A300 (290 death, 1988) Misleading output of the tracking software THERAC-25 Radiation Therapy (1985) 2 cancer patients at East Texas Cancer center received fatal overdoses

Software bug On average, 1-5 bugs per KLOC (thousand lines of code) In mature software More than 10 bugs in prototypes Windows2000 35MLOC 63K known bugs at the time of release 2 bugs per KLOC $59.5B loss due to bugs in US 2002 (estimation by NIST) It is not feasible to remove all bugs But try to reduce critical bugs

Approach to reduce bugs Testing Feed input to software and run it to see whether its behavior is as expected Limitations Impossible to cover all cases Test oracles (what is expected) Static checking Identify specific problems (e.g., memory leak) in the software by scanning the code or all possible paths Limited problem types (oracles) False positives

Approach to reduce bugs Formal Proof Formally prove that the program implements the specification Limitations Difficult to have a formal specification (oracle) The proof does not guarantee the correctness of implementation Inspection Manually review the code to detect faults Limitations: Hard to evaluate (oracle) Huge manual effort

Answer is testing, why? “50% of my employees are testers, and the rest spends 50% of their time testing” ---- Bill Gates, 1995 More reliable than inspection, relatively cheap Actually in the old days, when testing is expensive, inspection was the major answer You get what you pay (linear rewards) Compared to other 3 approaches Inspection, static checking, formal proof

Testing: Concepts Test case Test oracle Test suite Test script Test driver Test result Test coverage

Testing: Concepts Test case Test oracle An execution of the software with a given list of input values Include: Input values, sometimes fed in different steps Expected outputs Test oracle The expected outputs of software by feeding in a list of input values A part of test cases Hardest problem in auto-testing: test oracle problem

Testing: Concepts Test suite Test Script A collection of test cases Usually these test cases share similar pre-requisites and configuration Usually can be run together in sequence Different test suites for different purposes Smoke test, Certain platforms, Certain feature, performance, … Test Script A script to run a sequence of test cases or a test suite automatically

Testing: Concepts Test Driver Test Coverage A software framework that can load a collection of test cases or a test suite It can usually handle the configuration and comparison between expected outputs and actual outputs Test Coverage A measurement to evaluate how well the testing is done The measure can be based on multiple elements Line Branch …

Granularity of Testing: V-model

Granularity of testing Unit Testing Test of a single module Integration Testing Test the interaction between modules System Testing Test the system as a whole, by developers on test cases

Unit testing Testing of an basic module of the software A function, a class Typical problems revealed Local data structures Algorithms Boundary conditions Error handling

Unit test framework xUnit Created by Kent Beck in 1989 This is the same guy we mentioned in XP, design patterns The first one was sUnit (for smalltalk) Junit - The most popular xUnit framework There are about 70 xUnit frameworks for corresponding languages Never in the annals of software engineering was so much owed by so many to so few lines of code -------Martin Fowler

Unit Test Framework System under test: the system/module/component we are testing Test Fixture: SUT + DOC Test Method: The actual code of the test Test Case: A collection of tests with common purpose/setup

Writing a Test Case public class VectorTest extends TestCase { // extending Junit TestCase protected Vector fEmpty; protected Vector fFull; protected void setUp() { // executed before every test fEmpty= new Vector(); // Generate SUTs fFull= new Vector(); } @Test // annotation: tell Junit a test method public void testCapacity() { // a test method int size= fFull.size(); for (int i= 0; i < 100; i++){ fFull.addElement(new Integer(i)); assertTrue(fFull.size() == 100+size); //assertion, compare output with expected

Assertions public void testCapacity() { // a test method …. assertTrue(fFull.size() == 100+size); //assertion } If assertion fails: Assertion failed: myTest.java:150 (expected true but was false) Not so good! Try: assertEquals(100+size, fFull.size()); //expected value first Assertion failed: myTest.java:150 (expected 102 but was 103) Better! Try: assertEquals(“list length”, 100+size, fFull.size()); Assertion failed: myTest.java:150 (list length expected 102 but was 103)

Assertions Extend TestCase and write your own assertions AssertStringContains, AssertArrayEquals, … Use fail(String) to fail a test with certain message Junit creates one instance of TestCase per test method public void testRemoveAll() { fFull.removeAllElements(); fEmpty.removeAllElements(); assertTrue(fFull.isEmpty()); assertTrue(fEmpty.isEmpty()); }

Test failures Fail assertion or unhandled exception In JUnit, each test case is executed in a try-catch Why? Avoid one fail test to affect the following tests Test methods are independent in JUnit The order of executing test methods should not affect the test results JUnit achieve this by setup and tear down

Tear down void setUp() { Consider the following test code File f = open(“foo”); File b = open(“bar”); } void testAAA() { try { use f and b } finally { clean&close f, b void testBBB() { Consider the following test code void setUp() { File f = open(“foo”); File b = open(“bar”); } void testAAA() { use f and b void testBBB(){ Better? Problems?

Tear down Consider the following test code void setUp() { File f = open(“foo”); File b = open(“bar”); } void testAAA() { use f and b void testBBB(){ void tearDown{ clean&close f, b void setUp() { File f = open(“foo”); File b = open(“bar”); } … void tearDown{ try{ clean&close f }catch{ the same for b Problems?

Tear down If tear down is not complete, a test failure may affect the following test cases Recover the changes done to global data that are not well handled by the setup Database, files, network, global variables Clean resources Caution of exceptions in tear down itself

Integration Testing Big Bang Top down Bottom Up

Big Bang! Prepare all relevant components Usage Scenario Data, Global variables… Pray! Usage Scenario Quite common in small projects Requires no extra effort for integration Difficult to locate a fault

Top down strategy Feature decomposition A hierarchical structure of all software features

Top down strategy Focus on the validation of the whole system first Test an empty system with no components at first All components are replaced with test doubles, e.g., stubs Gradually add components Until all components are added

Top down strategy Advantages Disadvantages Easier to understand the process of the integration May have a working system earlier (or always have a working system): important for modern development, such as XP Disadvantages Requires to write test stubs Centralized, and the integration cannot be done in parallel

Bottom-up strategy Focus on the integration of lowest units at first Start from an unit depending nothing else When all sub-unit of a component are integrated, integrate the component Until the whole system is built 30

Bottom-up strategy Advantages Issues No test stub is required Requires test driver but may re-use unit test cases (view the whole component as a unit) Support parallel integration Issues No working system is available until the end Some issues emerge at the end

System testing - functional Test the system as a whole Usually test against requirements (specifications) For each item in the specification Work out a test case and a test oracle Test boundary values Test with invalid inputs Test with environment errors

GUI testing Testing Graphics User Interface is easier But harder to automate And harder to compare results with oracles Manual testing is still widely performed for GUI testing Manually explore the user interface Record the steps in the test for future testing Observe the GUI for errors

GUI testing Record and Replay Screen record and replay Record click on the screen and keyboard inputs Replay all the clicks and inputs Not robust, affected by screen size, resolution, resize, … Event record and replay Record all the UI events in the UI framework (swing, MFC, android etc.), and outputs (texts) in the UI Re-trigger all the events and compare the UI texts More robust, but requires more preparation and overhead https://en.wikipedia.org/wiki/Comparison_of_GUI_testing_tools

System testing - nonfunctional Platforms OS, database, application server, browser Compatibility is a huge problem Performance Response time Overload …

Test Coverage After we have done some testing, how do we know the testing is enough? The most straightforward: input coverage # of inputs tested / # of possible inputs Unfortunately, # of possible inputs is typically infinite Not feasible, so we need approximations…

Code Coverage Basic idea: Definition: Criteria Bugs in the code that has never been executed will not be exposed So the test suite is definitely not sufficient Definition: Divide the code to elements Calculate the proportion of elements that are executed by the test suite Criteria Statement (basic block) coverage, are they the same? Branch coverage (cover all edges in a control flow graph), same with basic block coverage? Data flow coverage

Example branch coverage vs statement coverage

Example branch coverage vs statement coverage Only 1 vs 0, 1

Statement Coverage in Practice Microsoft reports 80-90% statement coverage Safely-critical software must achieve 100% statement coverage Usually about 85% coverage, 100% for large systems is usually very hard Coverage is used to build the confidence on test suites Coverage does not guarantee correctness

More metrics to measure test cases Academy Mutation test Industry Requirement coverage program mutated programs test suite requirement test suite

This class Quality engineer Faults and their detection approaches Test Unit test Integration test System test Test coverage

Next class Quality engineer