Verificação e Validação de Software Departamento de Informática Faculdade de Ciências da Universidade de Lisboa
Eduardo Marques, Vasco Thudichum Vasconcelos
Syntax-based test coverage (part 2)
- grammar-based testing -
Syntax-based test coverage (part 2) - grammar-based testing - - - PowerPoint PPT Presentation
Syntax-based test coverage (part 2) - grammar-based testing - Basic grammar concepts Syntax-based Coverage Criteria Specification-based Grammars Input Space Grammars Verificao e Validao de Software Departamento de Informtica
Verificação e Validação de Software Departamento de Informática Faculdade de Ciências da Universidade de Lisboa
Eduardo Marques, Vasco Thudichum Vasconcelos
Grammar-based testing
Inputs for the SUT are many times (or can be seen as) defined by a grammar. Testing the SUT with valid inputs: exercise productions of the grammar according to some criterion. Testing the SUT with invalid inputs: consider grammar-based mutations are also considered to test the SUT with invalid inputs.
Examples
XML program data (in particular XML data with associated XML schemas) Programs written in a programming language (to test compilers) ! Assorted data formats and instances of them (JSON, ASN.1, …) …
2
expr ::= id | num | expr op expr id ::= letter | letter id num ::= digit | digit num
letter ::= a | … | z digit ::= 0 | 1 | 2 | … | 9
root symbol terminal symbols non-terminal symbols production rule 6 non-terminal symbols 40 (4+26+10) terminal symbols 47 production rules (3+2+2+4+26+10)
3
A simple grammar for a toy language of arithmetic expressions in BNF notation
Sample derivations:
a expr => id => letter => a 43 expr => num => digit num => 4 num => 4 digit => 43 ab+12 expr => expr op expr => expr + expr => ... => ab+12
4
expr expr expr
+ id num letter id a b letter 1 2 digit num digit
Syntax tree for
ab+12 expr ::= id | num | expr op expr id ::= letter | letter id num ::= digit | digit num
letter ::= a | … | z digit ::= 0 | 1 | 2 | … | 9
Terminal Symbol Coverage (TSC) TR contains each terminal in the grammar. One test case per terminal. Toy language example: 40 test requirements Production Coverage (PDC) TR contains each production rule in the grammar. One test case per production (hence PDC subsumes TSC). Toy language example: 47 test requirements Derivation Coverage (DC) TR contains every possible string that can be derived from the grammar. One test case per derivation required. Not practical - TR usually infinite as in our toy language. When applicable, DC subsumes PDC.
5
Suppose we wish to test a parser or interpreter for the example toy language.
TSC but not PDC.
6
expr ::= id | num | expr op expr id ::= letter | letter id num ::= digit | digit num
letter ::= a | … | z digit ::= 0 | 1 | 2 | … | 9
a b … z (26 tests) 0 1 … 9 (10 tests) a+b a-b a*b a/b (4 tests) PDC is not satisfied since no test case covers productions id ::= letter id or num ::= digit num
ab 12
7
expr ::= id | num | expr op expr id ::= letter | letter id num ::= digit | digit num
letter ::= a | … | z digit ::= 0 | 1 | 2 | … | 9
Terminal and nonterminal deletion: remove a terminal or nonterminal symbol from a production. Terminal and non-terminal duplication: duplicate a terminal or nonterminal symbol in a production. Terminal replacement: replace a terminal by another terminal. Non-terminal replacement
8
9
expr ::= id | num | expr op expr | ε | op expr | expr expr | expr op id ::= letter | letter id num ::= digit | digit num
letter ::= a | … | z digit ::= 0 | 1 | 2 | … | 9
empty string mutant productions resulting from nonterminal deletion for expr productions
expr ::= id | num | expr op expr id ::= letter | letter id num ::= digit | digit num
letter ::= a | … | z digit ::= 0 | 1 | 2 | … | 9
11
expr ::= id | num | expr op expr | id id | num num | expr expr op expr | expr op op expr | expr op expr expr id ::= letter | letter id num ::= digit | digit num
letter ::= a | … | z digit ::= 0 | 1 | 2 | … | 9 mutant productions resulting from nonterminal duplication
A&O, Figure 5.4
A&O, Figure 5.5
A&O, Figure 5.5
A&O, Figure 5.5
A&O, Figure 5.5
A&O, Figure 5.8
A&O, Figure 5.9
<xs:element name="book" maxOccurs="unbounded"> … <xs:element name="ISBN" type="xs:isbnType" minOccurs=“0"/> <xs:element name="price" type=“xs:decimal" fractionDigits=“2” minInclusive=“0”/> … </xs:element>
<xs:element name="book" maxOccurs="unbounded"> … <xs:element name="ISBN" type="xs:isbnType" minOccurs=“0"/> <xs:element name="year" type=“yearType"/> … </xs:element> <xs:simpleType name=“yearType"> <xs:restriction base="xs:int"> <xs:totalDigits value=“4"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="isbnType"> <xs:restriction base=“xs:string"> <xs:pattern value="[0-9]{10}"/> </xs:restriction> </xs:simpleType>