Syntax-Based Testing Mingzhe Du Hongying Du Dharani Chintapatla.

Slides:



Advertisements
Similar presentations
Mutation Testing. Mutation testing is a fault-based testing technique. It has been empirically and theoretically validated that a program will be well.
Advertisements

1 Software Testing and Quality Assurance Lecture 9 - Software Testing Techniques.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
Introduction to Software Testing Chapter 9.1 Syntax-based Testing Paul Ammann & Jeff Offutt
Debugging and Injecting Course Software Testing & Verification 2014/15 Wishnu Prasetya The debugging part uses Andreas Zeller’s slides. This is extra.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Introduction to Software Testing Chapter 5.2 Program-based Grammars Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 5.5 Input Space Grammars Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 9.4 Model-Based Grammars Paul Ammann & Jeff Offutt
Imperative Programming
Introduction to Software Testing Chapter 2.4 Graph Coverage for Design Elements Paul Ammann & Jeff Offutt
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Software Testing and Maintenance Lecture 4 Graph Coverage for Design Element Paul Ammann & Jeff Offutt Instructor: Hossein Momeni Mazandaran.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Software testing techniques Software testing techniques Mutation testing Presentation on the seminar Kaunas University of Technology.
637 – Introduction (Ch 1) Introduction to Software Testing Chapter 1 Jeff Offutt Information & Software Engineering SWE 437 Software Testing
Introduction to Software Testing Chapter 9.3 Integration and Object- Oriented Testing Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 5.1 Syntax-based Testing Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 5.3 Integration and Object-Oriented Testing Paul Ammann & Jeff Offutt
1 Graph Coverage (4). Reading Assignment P. Ammann and J. Offutt “Introduction to Software Testing” ◦ Section
C++ Programming Basic Learning Prepared By The Smartpath Information systems
CPS 506 Comparative Programming Languages Syntax Specification.
Software Testing Integration and Object-Oriented Testing.
Introduction to Software Testing Chapters 1-5 Coverage Summary Paul Ammann & Jeff Offutt
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Introduction to Software Testing Paul Ammann & Jeff Offutt Updated 24-August 2010.
Introduction to Software Testing (2nd edition) Chapter 7.4 Graph Coverage for Design Elements Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 5.3 Integration and Object-Oriented Testing Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 5.3 Integration and Object-Oriented Testing Paul Ammann & Jeff Offutt
Software Testing Syntax-based Testing. Syntax Coverage Four Structures for Modeling Software Graphs Logic Input Space Syntax Use cases Specs Design Source.
Introduction to Software Testing Chapter 9.2 Program-based Grammars Paul Ammann & Jeff Offutt
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
By Mr. Muhammad Pervez Akhtar
Classes, Interfaces and Packages
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Mutation Testing Breaking the application to test it.
MUTACINIS TESTAVIMAS Benediktas Knispelis, IFM-2/2 Mutation testing.
Software Testing and Quality Assurance Syntax-Based Testing (2) 1.
Introduction to Software Testing (2nd edition) Chapter 5 Criteria-Based Test Design Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 9.2 Program-based Grammars
Mutation Testing Moonzoo Kim School of Computing KAIST
Java Primer 1: Types, Classes and Operators
Input Space Partition Testing CS 4501 / 6501 Software Testing
Mutation testing Julius Purvinis IFM-0/2.
Graph Coverage for Design Elements CS 4501 / 6501 Software Testing
Syntax-based Testing CS 4501 / 6501 Software Testing
Introduction to Software Testing Chapter 5.1 Syntax-based Testing
Overloading and Constructors
Introduction to Software Testing Chapter 9.2 Program-based Grammars
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 5.2 Program-based Grammars
Software Testing Syntax-based Testing.
Introduction to Software Testing Chapter 5.1 Syntax-based Testing
Mutation Testing Moonzoo Kim School of Computing KAIST
Overloading Each method has a signature: its name together with the number and types of its parameters Methods Signatures String toString()
Mutation Testing Faults are introduced into the program by creating many versions of the program called mutants. Each mutant contains a single fault. Test.
Presentation transcript:

Syntax-Based Testing Mingzhe Du Hongying Du Dharani Chintapatla

Syntax-Based Testing Syntax-Based Testing Introduction Program-Based Grammers Integration and Object Oriented testing

Using the Syntax to Generate Tests Lots of software artifacts follow strict syntax rules The syntax is often expressed as some sort of grammar 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)

Grammar Coverage Criteria Software engineering makes practical use of automata theory in several ways –Programming languages defined in BNF –Program behavior described as finite state machines –Allowable inputs defined by grammars A simple regular expression: (G s n | B t n)* ‘*’ is closure operator, zero or more occurrences ‘|’ is choice, either one can be used Any sequence of “G s n” and “B t n” ‘G’ and ‘B’ could be commands, methods, or events ‘s’, ‘t’, and ‘n’ could represent arguments, parameters, or values ‘s’, ‘t’, and ‘n’ could be literals or a set of values

BNF Grammars Stream ::= action* action ::= actG | actB 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” Non-terminals Terminals Production rule Start symbol

Using Grammars Stream ::= action action * ::= actG action* ::= G s n action* ::= G digit 1-3 digit 2. digit 2. digit 2 action* ::= G digitdigit digitdigit.digitdigit.digitdigit action* ::= G action* … G B G B

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”

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

Mutants and Ground Strings The key to mutation testing is the design of the mutation operators –Well designed operators lead to powerful testing Sometimes mutant strings are based on ground strings Sometimes they are derived directly from the grammar –Ground strings are used for valid tests –Invalid tests do not need ground strings Valid Mutants Ground Strings Mutants G B B B Invalid Mutants B

Program-Based Grammers Hongying Du

Applying Syntax-based Testing to Programs Syntax-based testing criteria originated with programs and have been used most with programs BNF coverage criteria are most commonly used to test compilers –Testing compilers is very complicated Millions of correct programs ! Compilers must recognize and reject incorrect programs –BNF criteria can be used to generate programs to test all language features that compilers must process –This is a very specialized application and not discussed in detail Mutation testing criteria are most commonly used for unit testing of methods and integration testing of classes

Mutation testing 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) Once mutants are defined, tests must be found to cause mutants to fail when executed, this is called “killing mutants”

Program-based Grammars Original Method int Min (int A, int B) { int minVal; minVal = A; if (B < A) { minVal = B; } return (minVal); } // end Min 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 minVal = failOnZero (B); } return (minVal); } // end Min 6 mutants Each represents a separate program Test: (A = 5, B = 3)

Killing Mutants 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) 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.

Syntax-Based Coverage Criteria Mutation Coverage (MC) : For each m M, TR contains exactly one requirement, to kill m. Mutation Coverage (MC) : For each m  M, TR contains exactly one requirement, to kill m. The RIP model: 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 …

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

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

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

Mutation Operators for Java Each occurrence of one of the arithmetic operators +, -,*, /, and % is replaced by each of the other operators. In addition, each is replaced by the special mutation operators leftOp, and rightOp. 2. AOR –– Arithmetic Operator Replacement: Each arithmetic expression (and subexpression) is modified by the functions abs(), negAbs(), and failOnZero(). 1. ABS –– Absolute Value Insertion: E.g. x = a + b; can be mutated to x = a - b; x = a * b; x = a / b; x = a; x = b; x = a % b; E.g. x = 3 * a; can be mutated to x = 3 * abs (a); x = 3 * -abs (a); x = 3 * failOnZero (a);

Mutation Operators for Java Each occurrence of one of the relational operators (, ≥, ==, ≠) is replaced by each of the other operators and by falseOp and trueOp. 3. ROR –– Relational Operator Replacement: E.g. if (m > n) can be mutated to if (m >= n) if (m < n) if (m <= n) if (m = = n) if (m != n) if (false) if (true) Each occurrence of one of the logical operators (and - &&, or - ||, and with no conditional and - &, or with no conditional or - |, exclusive or - ^) is replaced by each of the other operators; in addition, each is replaced by falseOp, trueOp, leftOp, and rightOp. 4. COR –– Conditional Operator Replacement: E.g. if (a && b) can be mutated to If (a || b) if (a & b) if (a | b) if ( a ^ b) if (false) if (true) if (a) if (b)

Mutation Operators for Java 5. SOR –– Shift Operator Replacement: Each occurrence of one of the shift operators >, and >>> is replaced by each of the other operators. In addition, each is replaced by the special mutation operator leftOp. Each occurrence of one of the logical operators (bitwise and - &, bitwise inclusive or - |, bitwise exclusive or - ^) is replaced by each of the other operators; in addition, each is replaced by leftOp and rightOp. 6. LOR –– Logical Operator Replacement: E.g. x = m & n; can be mutated to x = m | n; x = m ^ n; x = m; x = n; E.g. x = m << a; can be mutated to x = m >> a; x = m >>> a; x = m;

Mutation Operators for Java Each occurrence of one of the assignment operators (+=, -=, *=, /=, %=, &=, |=, ^=, >=, >>>=) is replaced by each of the other operators. 7. ASR –– Assignment Operator Replacement: 8. UOI –– Unary Operator Insertion: Each unary operator (arithmetic +, arithmetic -, conditional !, logical ~) is inserted in front of each expression of the correct type. E.g. x += 3; can be mutated to X -= 3; x *= 3; x /= 3; x %= 3; x &= 3; x |= 3; x ^= 3; x >= 3; x >>>= 3; E.g. x = 3 * a; can be mutated to x = 3 * +a; x = 3 * -a; x = +3 * a; x = -3 * a;

Mutation Operators for Java Each unary operator (arithmetic +, arithmetic -, conditional !, logical~) is deleted. 9. UOD –– Unary Operator Deletion: Each variable reference is replaced by every other variable of the appropriate type that is declared in the current scope. 10. SVR –– Scalar Variable Replacement: E.g. if !(a < -b) can be mutated to if !(a > -b) if !(a > b) E.g. x = a * b; can be mutated to x = a * a; a = a * b; x = x * b; x = a * x; x = b * b; b = a * b;

Mutation Operators for Java 11. BSR –– Bomb Statement Replacement: Each statement is replaced by a special Bomb() function. E.g. x = a * b; can be mutated to Bomb();

Integration and Object Oriented testing Dharani Chintapatla

Integration and Object-Oriented Testing In Java, testing the way classes, packages and components are connected –“Component” is used as a generic term This tests features that are unique to object-oriented programming languages –inheritance, polymorphism and dynamic binding Integration testing is often based on couplings – the explicit and implicit relationships among software components Integration Testing Testing connections among separate program units

Integration Mutation Faults related to component integration often depend on a mismatch of assumptions –Callee thought a list was sorted, caller did not –Callee thought all fields were initialized, caller only initialized some of the fields –Caller sent values in kilometers, callee thought they were miles Integration mutation focuses on mutating the connections between components –Sometimes called “interface mutation” –Both caller and callee methods are considered

Four Types of Mutation Operators Change a calling method by modifying values that are sent to a called method Change a calling method by modifying the call Change a called method by modifying values that enter and leave a method –Includes parameters as well as variables from higher scopes (class level, package, public, etc.) Change a called method by modifying return statements from the method

Integration Mutation Operators—Example 1. IPVR – Integration Parameter Variable Replacement MyObject a, b;... callMethod (a);  callMethod (b); 2. IUOI – Integration Unary Operator Insertion callMethod (a);  callMethod (a++);

Integration Mutation Operators—Example 3. IPEX – Integration Parameter Exchange Max (a, b);  Max (b, a); 4. IMCD – Integration Method Call Deletion X = Max (a, b);  X = new Integer (3); 5. IREM – Integration Return Expression Modification int myMethod () { return a;  return ++a; }

OO Mutation Operators—Example 1. AMC – Access Modifier Change point private int x;  1 public int x;  2 protected int x;  3 int x;

OO Mutation Operators—Example 3. HVI – Hiding Variable Insertion colorpoint  1 int x;  2 int y; point int x; int y; 2. HVD – Hiding Variable Deletion point int x; int y; colorpoint int x;  1 // int x; int y;  2 // int y;

OO Mutation Operators—Example 4. OMD – Overriding Method Deletion5. OMM – Overriding Method Moving point void set (int x, int y) colorpoint void set (int x, int y)  // void set (int x, int y) point void set (int x, int y) { width = 5;…} colorpoint void set (int x, int y) { super.set (x, y); width = 10;}  { width=10; super.set (x, y); }

OO Mutation Operators—Example 6. OMR – Overriding Method Rename point … void set (int x, int y)  void setP (int x, int y) … void setDimension (int d) { … set (x, y);  setP (x, y); … } colorpoint … void set (int x, int y) point p; p = new colorpoint (); … p.Set (1, 2); p.setDimension (3); 7. SKD – Super Keyword Deletion point int getX() colorpoint int getX () { return super.x;  return x; }

OO Mutation Operators—Example 8. PCD – Parent Constructor Deletion point point (int x, int y) … colorpoint colorpoint (int x, int y, int color) { super (x, y);  // super (x, y); … }

OO Mutation Operators—Example 9. ATC – Actual Type Change point point p; p = new point ();  p = new colorpoint (); colorpoint 10. DTC – Declared Type Change point colorpoint point p;  colorpoint p; p = new colorpoint ();

OO Mutation Operators—Example 11. PTC – Parameter Type Change point boolean equals (point p) {... }  boolean equals (colorpoint p) {...} colorpoint 12. RTC – Reference Type Change point p; colorpoint cp = new colorpoint (0, 0); point3D p3d = new point3D (0, 0, 0); p = cp;  p = p3d; point colorpointpoint3D

OO Mutation Operators—Example 13. OMR – Overloading Method Change point point3D void set (int x, int y) { S1 } void set (int x, int y, int z) { S2 }  void set (int x, int y, int z) { S1 } 14. OMD – Overloading Method Deletion point point3D void set (int x, int y) { …}  // void set (int x, int y) { …} void set (int x, int y, int z) { … }

OO Mutation Operators—Example 16. ANC – Argument Number Change point3D p; p.set (1, 2, 3);  p.set (2, 3);  p.set (3); point point3D void set (int x, int y, int z); void set (int x, int y); void set (int z); 15. AOC – Argument Order Change point3D p; p.set (1, 2, ‘t’);  p.set (‘t’, 1, 2); point point3D void set (int x, int y, char c); void set (char a, int x, int y);

OO Mutation Operators—Example 17. JTD – This Keyword Deletion point … void set (int x, int y) { this.x = x;  1 x = x; this.y = y;  2 y = y; } … 18. JSD – Static Modifier Change point public static int x = 0;  1 public int x = 0; public int Y = 0;  2 public static int y = 0; …

OO Mutation Operators—Example 19. VID –Variable Initialization Deletion point int x = 0;  int x; … 20. DCD – Default Constructor Delete point point() { … }  // point() { … } …

References Introduction to software testing, P. Ammann J. Offutt slides

java mujava.gui.GenMutantsMain

java mujava.gui.RunTestMain

Thanks