Introduction to Software Testing Chapter 5.1 Syntax-based Testing

Similar documents
Program-based Mutation Testing

DRAFT: Prepublication draft, Fall 2014, George Mason University Redistribution is forbidden without the express permission of the authors

Introduction to Software Testing Chapter 2, Sections: 2.1 & 2.2 Overview Graph Coverage Criteria

Introduction to Software Testing Chapter 2.1, 2.2 Overview Graph Coverage Criteria Paul Ammann & Jeff Offutt

What is Mutation Testing? Mutation Testing. Test Case Adequacy. Mutation Testing. Mutant Programs. Example Mutation

Introduction to Software Testing Chapter 4 Input Space Partition Testing

White Box Testing III

Introduc)on to So,ware Tes)ng (2nd edi(on) Overview Graph Coverage Criteria. Paul Ammann & Jeff OffuA. hap:// so,waretest/

MTAT : Software Testing

MTAT : Software Testing

Overview Graph Coverage Criteria

Introduction to Software Testing Chapter 3, Sec# 1 & 2 Logic Coverage

Introduction to Software Testing Chapter 3.1, 3.2 Logic Coverage Paul Ammann & Jeff Offutt

Introduction to Software Testing Chapter 3.1, 3.2 Logic Coverage Paul Ammann & Jeff Offutt

Part I: Preliminaries 24

Introduction to Software Testing Chapter 2.4 Graph Coverage for Design Elements Paul Ammann & Jeff Offutt

CS 520 Theory and Practice of Software Engineering Fall 2018

Introduction to Software Testing Chapter 3, Sec# 3.3 Logic Coverage for Source Code

Testing! Prof. Leon Osterweil! CS 520/620! Spring 2013!

Automa'c Test Genera'on

CMPSCI 521/621 Homework 2 Solutions

Software Testing Fundamentals. Software Testing Techniques. Information Flow in Testing. Testing Objectives

Introduction to Software Testing Chapter 2, Sec#: 2.5 Graph Coverage for Specifications

Lecture 2. White- box Tes2ng and Structural Coverage (see Amman and Offut, Chapter 2)

Testing. ECE/CS 5780/6780: Embedded System Design. Why is testing so hard? Why do testing?

What is Mutation Testing?

Logic Coverage for Source Code

Testing: Coverage and Structural Coverage

Lecture 2. White- box Tes2ng and Structural Coverage (see Amman and Offut, Chapter 2)

Faults, Errors, Failures

Testing Object Oriented Software 2010

CMPT 473 Software Quality Assurance. Graph Coverage. Nick Sumner

GENERATING COST-EFFECTIVE CRITERIA-BASED TESTS FROM BEHAVIORAL MODELS

Testing Role in Unified Approach Coverage: Structural/Coverage Model Based Test Generation from Model Checking (project) Interaction of

Introduction to Software Testing Chapter 2.3 Graph Coverage for Source Code. Paul Ammann & Jeff Offutt

CISC327 - So*ware Quality Assurance. Lecture 13 Black Box Unit

Multi-Objective Higher Order Mutation Testing with Genetic Programming

linaye/gl.html

MTAT : Software Testing

Class-Component Testability Analysis

Test Case Specifications and Test adequacy. Research Methods - Barbara Russo SwSE - Software and Systems Engineering

CISC327 - So*ware Quality Assurance

Input Validation Testing: A Requirements-Driven, System level, Early Lifecycle Technique

Computer Science and Software Engineering University of Wisconsin - Platteville 9-Software Testing, Verification and Validation

Applying Mutation Testing to XML Schemas

MTAT : Software Testing

Self-checking software insert specifications about the intent of a system

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

MTAT : Software Testing

White-Box Testing Techniques

Testing: Coverage and Structural Coverage

Darshan Institute of Engineering & Technology for Diploma Studies

What is software testing? Software testing is designing, executing and evaluating test cases in order to detect faults.

Ensuring the Observability of Structural Test Obligations

6. Test-Adequacy. Assessment Using Control Flow and Data Flow. Andrea Polini

Combinatorial Clause Coverage CoC

Potential Errors and Test Assessment in Software Product Line Engineering

1 Black Box Test Data Generation Techniques

Logic Coverage. Moonzoo Kim School of Computing KAIST. The original slides are taken from Chap. 8 of Intro. to SW Testing 2 nd ed by Ammann and Offutt

MTAT : Software Testing

Fault-based testing. Automated testing and verification. J.P. Galeotti - Alessandra Gorla. slides by Gordon Fraser. Thursday, January 17, 13

Second assignment came out Monday evening. Find defects in Hnefetafl rules written by your classmates. Topic: Code Inspection and Testing

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m.

Homework #1, on the class web pages later today

Testing: Test design and testing process

Software Testing for Critical Systems

Symbolic Evaluation/Execution

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #13. Loops: Do - While

MTAT : Software Testing

Programming Embedded Systems

A Survey on Different Approaches for Efficient Mutation Testing

Advanced Test Coverage Criteria: Specify and Measure, Cover and Unmask

Using the code to measure test adequacy (and derive test cases) Structural Testing

Lecture 10: Introduction to Correctness

Introduction to Dynamic Analysis

Software Testing: Introduction

A Transformation-based Approach to Testing Concurrent Programs using UML Activity Diagrams

EVALUATING THE EFFECTIVENESS OF TEST COVERAGE CRITERIA USING MUTATION ANALYSIS. An evaluation of test coverage criteria in C#

Reading Assignment. Symbolic Evaluation/Execution. Move from Dynamic Analysis to Static Analysis. Move from Dynamic Analysis to Static Analysis

CS152 Programming Language Paradigms Prof. Tom Austin, Fall Syntax & Semantics, and Language Design Criteria

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

Test Oracles and Mutation Testing. CSCE Lecture 23-11/18/2015

Type Checking and Type Equality

Software Testing TEST CASE SELECTION AND ADEQUECY TEST EXECUTION

Program Analysis. Program Analysis

Handout 9: Imperative Programs and State

Modern Methods in Software Engineering. Testing.

An Introduction to Systematic Software Testing. Robert France CSU

4. An interpreter is a program that

EECS 481 Software Engineering Exam #1. You have 1 hour and 20 minutes to work on the exam.

Programming Embedded Systems

Verification Overview Testing Theory and Principles Testing in Practice. Verification. Miaoqing Huang University of Arkansas 1 / 80

CSE 403 Lecture 13. Black/White-Box Testing. Reading: Software Testing: Principles and Practices, Ch. 3-4 (Desikan, Ramesh)

Structural Testing. (c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 1

1 Introduction. 3 Syntax

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011

Coding and Unit Testing! The Coding Phase! Coding vs. Code! Coding! Overall Coding Language Trends!

Foundations: Syntax, Semantics, and Graphs

ON SOFTWARE TESTING AND SUBSUMING MUTANTS An empirical study. Master Degree Project in Computer Science Advanced level 15 credits Spring term 2014

Instance generation from meta-models (for model transformation testing)

Transcription:

Introduction to Software Testing Chapter 5.1 Syntax-based Testing Paul Ammann & Jeff Offutt http://www.cs.gmu.edu/~offutt/ softwaretest/

Ch. 5 : Syntax Coverage Four Structures for Modeling Software Graphs Logic Input Space Syntax Applied to Applied to Source FSMs Applied to Specs DNF Source Specs Source Models Design Use cases Integ Input Ammann & Offutt 2

Using the Syntax to Generate Tests (5.1) Lots of software artifacts follow strict syntax rules The syntax is often expressed as a grammar in a language such as BNF Syntactic descriptions can come from many sources Programs Integration elements Design documents Input descriptions Tests are created with two general goals Cover the syntax in some way Violate the syntax (invalid tests) Ammann & Offutt 3

Mutation as Grammar-Based Testing Grammar-based Testing UnMutated Derivations (valid strings) Mutated Derivations (invalid strings) Now we can define generic coverage criteria Grammar Mutation (invalid strings) Invalid Strings Ground String Mutation Valid Strings Ammann & Offutt 4

Stream ::= action* action ::= actg actb actg ::= G s n actb ::= B t n s ::= digit 1-3 t ::= digit 1-3 BNF Grammars Start symbol Non-terminals Production rule Terminals n ::= digit 2. digit 2. digit 2 digit ::= 0 1 2 3 4 5 6 7 8 9 Ammann & Offutt 5

Syntax-based Coverage Criteria The most common and straightforward use every terminal and every production at least once Terminal Symbol Coverage (TSC) : TR contains each terminal symbol t in the grammar G. Production Coverage (PDC) : TR contains each production p in the grammar G. PDC subsumes TSC Grammars and graphs are interchangeable PDC is equivalent to EC, TSC is equivalent to NC Other graph-based coverage criteria could be defined on grammar But have not Ammann & Offutt 6

Syntax-based Coverage Criteria A related criterion is the impractical one of deriving all possible strings Derivation Coverage (DC) : TR contains every possible string that can be derived from the grammar G. The number of TSC tests is bound by the number of terminal symbols 13 in the stream grammar The number of PDC tests is bound by the number of productions 18 in the stream grammar The number of DC tests depends on the details of the grammar 2,000,000,000 in the stream grammar! All TSC, PDC and DC tests are in the grammar how about tests that are NOT in the grammar? Ammann & Offutt 7

Mutation Testing Grammars describe both valid and invalid strings Both types can be produced as mutants A mutant is a variation of a valid string Mutants may be valid or invalid strings Mutation is based on mutation operators and ground strings Ammann & Offutt 8

What is Mutation? General View We are performing mutation analysis whenever we use well defined rules defined on syntactic descriptions to make systematic changes mutation operators grammars Applied universally or according to empirically verified distributions to the syntax or to objects developed from the syntax grammar ground strings Ammann & Offutt 9

Mutation Testing Ground string: A string in the grammar The term ground is used as a reference to algebraic ground terms Mutation Operator : A rule that specifies syntactic variations of strings generated from a grammar Mutant : The result of one application of a mutation operator A mutant is a string Ammann & Offutt 10

Killing Mutants When ground strings are mutated to create valid strings, the hope is to exhibit different behavior from the ground string This is normally used when the grammars are programming languages, the strings are programs, and the ground strings are pre-existing programs Killing Mutants : Given a mutant m M for a derivation D and a test t, t is said to kill m if and only if the output of t on D is different from the output of t on m The derivation D may be represented by the list of productions or by the final string Ammann & Offutt 11

Syntax-based Coverage Criteria Coverage is defined in terms of killing mutants Mutation Coverage (MC) : For each m M, TR contains exactly one requirement, to kill m. Coverage in mutation equates to number of mutants killed The amount of mutants killed is called the mutation score Ammann & Offutt 12

Syntax-based Coverage Criteria When creating invalid strings, we just apply the operators This results in two simple criteria It makes sense to either use every operator once or every production once Mutation Operator Coverage (MOC) : For each mutation operator, TR contains exactly one requirement, to create a mutated string m that is derived using the mutation operator. Mutation Production Coverage (MPC) : For each mutation operator, TR contains several requirements, to create one mutated string m that includes every production that can be mutated by that operator. Ammann & Offutt 13

Example Stream ::= action* action ::= actg actb Grammar actg ::= G s n actb ::= B t n s ::= digit 1-3 t ::= digit 1-3 n ::= digit 2. digit 2. digit 2 digit ::= 0 1 2 3 4 5 6 7 8 9 Ground String G 23 08.01.90 B 19 06.27.94 Mutants using MOC B 23 08.01.90 B 15 06.27.94 Mutation Operators Exchange actg and actb Replace digits with all other digits Mutants using MPC B 22 08.01.90 G 19 06.27.94 G 13 08.01.90 B 11 06.27.94 G 33 08.01.90 B 12 06.27.94 G 43 08.01.90 B 13 06.27.94 G 53 08.01.90 B 14 06.27.94 Ammann & Offutt 14

Mutation Testing The number of test requirements for mutation depends on two things The syntax of the artifact being mutated The mutation operators Mutation testing is very difficult to apply by hand Mutation testing is very effective considered the gold standard of testing Mutation testing is often used to evaluate other criteria Ammann & Offutt 15

Instantiating Grammar-Based Testing Grammar-Based Testing Program-based Integration Model-Based Input-Based Grammar String mutation Compiler testing Valid and invalid strings Program mutation Valid strings Mutants are not tests Must kill mutants String mutation Test how classes interact Valid strings Mutants are not tests Must kill mutants Includes OO String mutation FSMs Model checking Valid strings Traces are tests Grammar Input validation testing XML and others Valid strings String mutation Input validation testing XML and others Invalid strings No ground strings Mutants are tests Ammann & Offutt 16

Applying Syntax-based Testing to Programs Syntax-based criteria originated with programs and have been used most with programs BNF criteria are most commonly used to test compilers Mutation testing criteria are most commonly used for unit testing and integration testing of classes Ammann & Offutt 17

Instantiating Grammar-Based Testing Grammar-Based Testing Program-based Integration Model-Based Input-Based 5.2 Grammar String mutation Compiler testing Valid and invalid strings Program mutation Valid strings Mutants are not tests Must kill mutants String mutation Test how classes interact Valid strings Mutants are not tests Must kill mutants Includes OO String mutation FSMs Model checking Valid strings Traces are tests Grammar Input validation testing XML and others Valid strings String mutation Input validation testing XML and others Invalid strings No ground strings Mutants are tests Ammann & Offutt 18

Program-based Grammars (5.2.2) The original and most widely known application of syntax-based testing is to modify programs Operators modify a ground string (program under test) to create mutant programs Mutant programs must compile correctly (valid strings) Mutants are not tests, but used to find tests Once mutants are defined, tests must be found to cause mutants to fail when executed This is called killing mutants Ammann & Offutt 19

Killing Mutants Given a mutant m M for a ground string program P and a test t, t is said to kill m if and only if the output of t on P is different from the output of t on m. If mutation operators are designed well, the resulting tests will be very powerful Different operators must be defined for different programming languages and goals Testers can keep adding tests until all mutants have been killed Dead mutant : A test case has killed it Stillborn mutant : Syntactically illegal Trivial mutant : Almost every test can kill it Equivalent mutant : No test can kill it (equivalent to original program) Ammann & Offutt 20

Program-based Grammars Original Method int Min (int A, int B) { int minval; minval = A; if (B < A) { minval = B; } return (minval); } // end Min 6 mutants Each represents a separate program With Embedded Mutants int Min (int A, int B) { int minval; minval = A; 1 minval = B; if (B < A) 2 if (B > A) 3 if (B < minval) { minval = B; 4 Bomb (); 5 minval = A; 6 } return (minval); } // end Min Replace one variable with another Changes operator minval = failonzero (B); Immediate runtime failure if reached Immediate runtime failure if B==0 else does nothing Ammann & Offutt 21

Syntax-Based Coverage Criteria Mutation Coverage (MC) : For each m M, TR contains exactly one requirement, to kill m. The RIP model from chapter 1: Reachability : The test causes the faulty statement to be reached (in mutation the mutated statement) Infection : The test causes the faulty statement to result in an incorrect state Propagation : The incorrect state propagates to incorrect output The RIP model leads to two variants of mutation coverage Ammann & Offutt 22

Syntax-Based Coverage Criteria 1) Strongly Killing Mutants: Given a mutant m M for a program P and a test t, t is said to strongly kill m if and only if the output of t on P is different from the output of t on m 2) Weakly Killing Mutants: Given a mutant m M that modifies a location l in a program P, and a test t, t is said to weakly kill m if and only if the state of the execution of P on t is different from the state of the execution of m immediately on t after l Weakly killing satisfies reachability and infection, but not propagation Ammann & Offutt 23

Weak Mutation Weak Mutation Coverage (WMC) : For each m M, TR contains exactly one requirement, to weakly kill m. Weak mutation is so named because it is easier to kill mutants under this assumption Weak mutation also requires less analysis A few mutants can be killed under weak mutation but not under strong mutation (no propagation) In practice, there is little difference Ammann & Offutt 24

Weak Mutation Example Mutant 1 in the Min( ) example is: minval = A; 1 minval = B; if (B < A) minval = B; The complete test specification to kill mutant 1: Reachability : true // Always get to that statement Infection : A B Propagation: (B < A) = false // Skip the next assignment Full Test Specification : true (A B) ((B < A) = false) (A B) (B A) (B > A) (A = 5, B = 3) will weakly kill mutant 1, but not strongly Ammann & Offutt 25

Equivalent Mutation Example Mutant 3 in the Min() example is equivalent: minval = A; if (B < A) 3 if (B < minval) The infection condition is (B < A)!= (B < minval) However, the previous statement was minval = A Substituting, we get: (B < A)!= (B < A) This is a logical contradiction! Thus no input can kill this mutant Ammann & Offutt 26

1 boolean iseven (int X) 2 { 3 if (X < 0) 4 X = 0 - X; 4 X = 0; 5 if (double) (X/2) == ((double) X) / 2.0 6 return (true); 7 else 8 return (false); 9 } Strong Versus Weak Mutation Propagation : Reachability : X < 0 Infection : X!= 0 (X = -6) will kill mutant 4 under weak mutation ((double) ((0-X)/2) == ((double) 0-X) / 2.0)!= ((double) (0/2) == ((double) 0) / 2.0) That is, X is not even Thus (X = -6) does not kill the mutant under strong mutation Ammann & Offutt 27

Testing Programs with Mutation Prog Input test method Create mutants Run equivalence detector Generate test cases Run T on P Define threshold Automated steps no Run mutants: schema-based weak selective Threshold reached? Eliminate ineffective TCs Fix P no P (T) correct? yes Ammann & Offutt 28

Why Mutation Works Fundamental Premise of Mutation Testing If the software contains a fault, there will usually be a set of mutants that can only be killed by a test case that also detects that fault This is not an absolute! The mutants guide the tester to an effective set of tests A very challenging problem : Find a fault and a set of mutation-adequate tests that do not find the fault Of course, this depends on the mutation operators Ammann & Offutt 29

Changing No*ons of Tes*ng Old view focused on tes*ng at each so7ware development phase as being very different from other phases Unit, module, integra*on, system New view is in terms of structures and criteria Graphs, logical expressions, syntax, input space Test design is largely the same at each phase Crea*ng the model is different Choosing values and automa*ng Ammann & Offutt the tests is different 30 Introduction to Software Testing, Edition 2 (Ch

New : Test Coverage Criteria A tester s job is simple : Define a model of the software, then find ways to cover it g Test Requirements : Specific things that must be sa*sfied or covered during tes*ng g Test Criterion : A collec*on of rules and a process that define test requirements Introduction to Software Testing, Edition 2 (Ch Ammann & Offutt 31

Criteria Based on Structures Structures : Four ways to model software 1. Graphs 2. Logical Expressions 3. Input Domain Characterization (not X or not Y) and A and B A: {0, 1, >1} B: {600, 700, 800} C: {swe, cs, isa, infs} 4. Syntactic Structures Introduction to Software Testing, Edition 2 (Ch if (x > y) z = x - y; else z = 2 * x; Ammann & Offutt 32

Old View : Black and White Boxes Black-box tes*ng : Derive tests from external descrip*ons of the so7ware, including specifica*ons, requirements, and design White-box tes*ng : Derive tests from the source code internals of the so7ware, specifically including branches, individual condi*ons, and statements Model-based tes*ng : Derive tests from a model of the so7ware (such as a UML diagram) Introduction to Software Testing, Edition 2 (Ch Ammann & Offutt 33