Paul Ammann & Jeff Offutt

Slides:



Advertisements
Similar presentations
Introduction to Software Testing Chapter 1
Advertisements

Managing XML and Semistructured Data Lecture 12: XML Schema Prof. Dan Suciu Spring 2001.
1 Web Data Management XML Schema. 2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft:
Introduction to Software Testing Chapter 1 Paul Ammann & Jeff Offutt SUMMARY OF PARTS 1 AND 2 FROM LAST WEEK.
Introduction to Software Testing Chapter 2.6 Graph Coverage for Use Cases Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 5.5 Input Space Grammars Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 9.5 Input Space Grammars Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 2.6 Graph Coverage for Use Cases Paul Ammann & Jeff Offutt
SDPL 2003Notes 2: Document Instances and Grammars1 2.5 XML Schemas n A quick introduction to XML Schema –W3C Recommendation, May 2, 2001: »XML Schema Part.
CSE 636 Data Integration XML Schema. 2 XML Schemas W3C Recommendation: Generalizes DTDs Uses XML syntax Two documents: structure.
XML Schema Definition Language
XML Schemas. “Schemas” is a general term--DTDs are a form of XML schemas –According to the dictionary, a schema is “a structured framework or plan” When.
Introduction to Software Testing Chapter 9.1 Syntax-based Testing Paul Ammann & Jeff Offutt
Introduction to XML This material is based heavily on the tutorial by the same name at
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
XML-based Testing of Web Software Services Joint research with Wuxhi Xu, Juan Luo and Suet Chun Lee Jeff Offutt Software Engineering George Mason University.
Why XML ? Problems with HTML HTML design - HTML is intended for presentation of information as Web pages. - HTML contains a fixed set of markup tags. This.
Dr. Azeddine Chikh IS446: Internet Software Development.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation XML Schema 2 Lecturer.
SDPL 2005Notes 2.5: XML Schemas1 2.5 XML Schemas n Short introduction to XML Schema –W3C Recommendation, 1 st Ed. May, 2001; 2 nd Ed. Oct, 2004: »XML Schema.
New Perspectives on XML, 2nd Edition
Introduction to Software Testing Chapter 5.1 Syntax-based Testing Paul Ammann & Jeff Offutt
Schemas 1www.tech.findforinfo.com. What is a Schema a schematic or preliminary plan Description of a structure, details... 2www.tech.findforinfo.com.
An Introduction to XML Sandeep Bhattaram
XML 2nd EDITION Tutorial 4 Working With Schemas. XP Schemas A schema is an XML document that defines the content and structure of one or more XML documents.
Tutorial 13 Validating Documents with Schemas
Management of XML and Semistructured Data Lecture 11: Schemas Wednesday, May 2nd, 2001.
Introduction to Software Testing Chapters 1-5 Coverage Summary Paul Ammann & Jeff Offutt
Introduction to Software Testing Paul Ammann & Jeff Offutt Updated 24-August 2010.
1 Graph Coverage (6). Reading Assignment P. Ammann and J. Offutt “Introduction to Software Testing” ◦ Section
Introduction to XML Schema John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel: (x2073)
XSD: XML Schema Language Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Introduction to Software Testing Chapter 9.2 Program-based Grammars Paul Ammann & Jeff Offutt
Testing Web Services by XML Perturbation Joint research with Wuzhi Xu and Juan Luo Jeff Offutt Information & Software Engineering George Mason University.
Introduction to Software Testing (2nd edition) Chapter 5 Criteria-Based Test Design Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
XML: Extensible Markup Language
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 9.2 Program-based Grammars
Paul Ammann & Jeff Offutt
Use Case Model.
Input Space Partition Testing CS 4501 / 6501 Software Testing
Paul Ammann & Jeff Offutt
Graph Coverage for Specifications CS 4501 / 6501 Software Testing
Paul Ammann & Jeff Offutt
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
Syntax-based Testing CS 4501 / 6501 Software Testing
Introduction to Software Testing Chapter 5.1 Syntax-based Testing
Introduction to Software Testing Chapter 9.2 Program-based Grammars
Paul Ammann & Jeff Offutt
Design and Implementation of Software for the Web
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 5.2 Program-based Grammars
Test Driven Lasse Koskela Chapter 9: Acceptance TDD Explained
CS 3304 Comparative Languages
CS 3304 Comparative Languages
ISP Coverage Criteria CS 4501 / 6501 Software Testing
Graph Coverage for Specifications CS 4501 / 6501 Software Testing
Paul Ammann & Jeff Offutt
Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 5.1 Syntax-based Testing
Paul Ammann & Jeff Offutt
Chapter 10: Compilers and Language Translation
Input Data Validation for Web Applications
Presentation transcript:

Paul Ammann & Jeff Offutt http://www.cs.gmu.edu/~offutt/softwaretest/ Introduction to Software Testing Chapter 9.1 & 9.5 Grammar-based Testing Paul Ammann & Jeff Offutt http://www.cs.gmu.edu/~offutt/softwaretest/ This version modified for our undergrad class (SWE 437). It includes material from section 9.5.

Using Syntax to Generate Tests Lots of software artifacts follow strict syntax rules The syntax is often expressed as a grammar Commonly 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) Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

The set of allowable inputs to software Input Space Grammars Input Space The set of allowable inputs to software The input space can be described in many ways User manuals Unix man pages Method signature / Collection of method preconditions A language Most input spaces can be described as grammars Grammars are usually not provided, but creating them is a valuable service by the tester Testers often find errors when creating the grammar Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

Using Input Grammars Software should reject or handle invalid data Programs often do this incorrectly Some programs (rashly) assume all input data is correct Even if it works today … What about after maintenance changes ? What if the component is reused in a new program ? Consequences can be severe … The database can be corrupted Users are not satisfied Most security vulnerabilities are from unhandled exceptions … from invalid data Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

Deciding if input values can be processed by the software Validating Inputs Input Validation Deciding if input values can be processed by the software Before processing inputs, good programs check that the inputs are valid How should a program recognize invalid inputs ? What should a program do with invalid inputs ? If the input space is described as a grammar, a parser can check automatically This is very rare It is easy to write input checkers—but also easy to make mistakes Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

Representing Input Domains Desired inputs (goal domain) Described inputs (specified domain) Accepted inputs (implemented domain) Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

† More details are on : http://www.merriampark.com/anatomycc.htm Example Input Domains Goal domains are often irregular Goal domain for credit cards† First digit is the Major Industry Identifier First 6 digits and length specify the issuer Final digit is a “check digit” Other digits identify a specific account Common specified domain First digit is in { 3, 4, 5, 6 } (travel and banking) Length is between 13 and 16 Common implemented domain All digits are numeric † More details are on : http://www.merriampark.com/anatomycc.htm Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

Representing Input Domains goal domain specified domain This region is a rich source of software failures implemented domain Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

Input Space BNF Grammars (9.5.1) Input spaces can be expressed in many forms Grammars are common We will look at three grammar-based languages Regular expressions BNF grammars XML and Schema All are similar and can be used in different contexts Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

Initial Regular Expression Regular Expressions Consider bank software that processes a sequence of deposits and debits Inputs deposit 5306 $4.30 debit 0343 $4.14 deposit 5306 $7.29 Initial Regular Expression (deposit account amount | debit account amount) * Ready deposit debit FSM to represent the grammar Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

BNF Grammar for Bank Example Grammars are more expressive than regular expressions–they can capture more details bank ::= action* action ::= dep | deb dep ::= “deposit” account amount deb ::= “debit” account amount account ::= digit4 amount ::= “$” digit+ “.” digit2 digit ::= “0” | “1” | “2” | “3” | “4” | “5” | “6” | “7” | “8” | “9” Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

FSM for Bank Grammar deposit debit digit “.” $ Derive tests by systematically replacing each non-terminal with a production If the tester designs the grammar from informal input descriptions, do it early In time to improve the design You will almost always find mistakes and omissions Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

eXtensible Markup Language (XML) Software components that pass data must agree on format, types, and organization Web applications have unique requirements : Very loose coupling and dynamic integration Data passed directly between components XML allows data to be self-documenting Schema C1 C2 Parser XML File C3 Components 1, 2, and 3 can see the data format, contents, and structure Data sharing is independent of type Format is easy to understand Grammars are defined in schemas Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

schemas define input spaces for software components XML for Book Example <books> <book> <ISBN>0471043281</ISBN> <title>The Art of Software Testing</title> <author>Glen Myers</author> <publisher>Wiley</publisher> <price>50.00</price> <year>1979</year> </book> </books> XML messages are defined by grammars Schemas and DTDs Schemas can define types Schemas include “facets,” which refine the grammar schemas define input spaces for software components Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

XML Constraints – “Facets” Boundary Constraints Non-boundary Constraints maxOccurs enumeration minOccurs use length fractionDigits maxExclusive pattern maxInclusive nillable maxLength whiteSpace minExclusive unique minInclusive minLength totalDigits Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

Using Grammars to Design Tests This form of testing allows us to focus on interactions among the components Web services depend on XML The grammar is used to create valid as well as invalid tests The grammar is mutated The mutated grammar is used to generate new XML messages The XML messages are test cases Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

Book Grammar – Schema <xs:element name = “books”> <xs:complexType> <xs:sequence> <xs:element name = “book” maxOccurs = “unbounded”> <xs:element name = “ISBN” type = “isbnType” minOccurs = “0”/> <xs:element name = “author” type = “xs:string”/> <xs:element name = “title” type = “xs:string”/> <xs:element name = “publisher” type = “xs:string”/> <xs:element name = “price” type = “priceType”/> <xs:element name = “year” type = “yearType”/> </xs:sequence> </xs:complexType> </xs:element> Built-in types <xs:simpleType name = “priceType”> <xs:restriction base = “xs:decimal”> <xs:fractionDigits value = “2” /> <xs:maxInclusive value = “1000.00” /> </xs:restriction> </xs:simpleType> Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

Generating Tests Valid tests Invalid tests Generate tests as XML messages by deriving strings from grammar Take every production at least once Take choices … “maxOccurs = “unbounded” means use 0, 1 and more than 1 Invalid tests Mutate the grammar in structured ways Create XML messages that are “almost” valid This explores the gray space on the previous slide Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

Grammar-based Coverage Criteria The most common and straightforward criteria 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 Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

Generating Tests for Books The only choice in the books grammar is based on “minOccurs” Production coverage (PDC) requires two tests ISBN is present ISBN is not present The facets are used to generate values that are valid We also want values that are not valid … Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

Mutating Input Grammars (9.5.2) Modify an existing grammar, then generate strings that are “close to correct” Each mutated string is a test Possible mutations : Replace nonterminal symbols with other nonterminal symbols Replace terminal symbols with other terminal symbols Delete terminal and nonterminal symbols Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

New Bank Tests from Mutation Nonterminal Replacement dep ::= “deposit” account amount dep ::= “deposit” amount amount dep ::= “deposit” account digit deposit $1500.00 $3789.88 deposit 4400 5 Terminal Replacement amount ::= “$” digit+ “.” digit2 amount ::= “.” digit+ “.” digit2 amount ::= “$” digit+ “$” digit2 amount ::= “$” digit+ “1” digit2 deposit 4400 .1500.00 deposit 4400 $1500$00 deposit 4400 $1500100 Terminal and Nonterminal Deletion dep ::= “deposit” account amount dep ::= account amount dep ::= “deposit” amount dep ::= “deposit” account 4400 $1500.00 deposit $1500.00 deposit 4400 Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

Test Case Generation – Example Original Schema (Partial) <xs:simpleType name = “priceType”> <xs:restriction base = “xs:decimal”> <xs:fractionDigits value = “2” /> <xs:maxInclusive value = “1000.00” /> </xs:restriction> </xs:simpleType> Mutants : value = “3” value = “1” Mutants : value = “100” value = “2000” XML from Original Schema <books> <book> <ISBN>0-201-74095-8</ISBN> <price>37.95</price> <year>2002</year> </book> Mutant XML 1 <books> <book> <ISBN>0-201-74095-8</ISBN> <price>37.95 </price> <year>2002</year> </book> Mutant XML 2 <books> <book> <ISBN>0-201-74095-8</ISBN> <price>37.95</price> <year>2002</year> </book> Mutant XML 3 <books> <book> <ISBN>0-201-74095-8</ISBN> <price>37.95 </price> <year>2002</year> </book> Mutant XML 4 <books> <book> <ISBN>0-201-74095-8</ISBN> <price>37.95 </price> <year>2002</year> </book> 505 5 99.00 1500.00 Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt

Input Space Grammars Summary This application of mutation is fairly new Automated tools do not exist Can be used by hand in an “ad-hoc” manner to get effective tests Applications to special-purpose grammars very promising XML SQL HTML Introduction to Software Testing, edition 2 (Ch 9) © Ammann & Offutt