What is the general understanding of modelling and testing?
In brief, we come up with tests by looking at requirements and specifications, and thinking about the system – modelling it – in different ways.
What are the 4 main models for testing?
As covered in the lectures:
- Input Space Partitioning (Equivalence classes of inputs)
- Logic-based Testing (Look inside the parts of boolean expressions making up a decision point)
- Graph-based Testing (on Program Control Flows)
Syntax-based Testing
DONT REALLY NEED TO KNOW, THIS IS MORE A CHECKLIST OF WHAT WE HAVE COVERED
What is Syntax?
Rules and regulations for writing an artefact correctly
What is Semantics?
Its meaning and behaviour, dictating what a piece of code does when executed, rather than just how it’s written
What sort of things can be tested with syntax-based test methods
Anything thing that can be modelled by a syntactic description such as a grammar:
- Input commands eg command line applications (aws, docker, etc)
- Syntax of types eg email addresses, datetime format, URLs, passwords etc
- Data and file formats eg XML
Computer Program Syntax eg Java or Python programs etc
Understanding Grammar
REFER TO SLIDES FOR EXAMPLE
Where can we get syntactic descriptions from?
Syntactic descriptions can be obtained from many sources:
- program source code
- design documents
- input descriptions (e.g. file formats, network message formats, etc)
What are the two ways we can use grammars?
Grammars can be used to build recognizers (programs which decide whether a string is in the grammar – i.e., parsers) and also generators, which produce strings of symbols.
In other words as recognisers or generators
When to Use Grammars to Generate Tests
Need to determine when the best time is to apply the tests
What is the theory of grammar?
Grammars just give us a way of formally specifying what things are and are not syntactically correct
- Every grammar defines what is called a language
What is a language?
A language is a set of acceptable strings
REFER TO SLIDES FOR EXAMPLE
What is BNF (Backus-Naur Form)?
REFER TO SLIDES FOR EXAMPLE
What is the notation of grammar - terminal symbols?
The things in quotes are called terminal symbols – they are the equivalent of “words” in our language.
- They are like atoms, in that they are the smallest, indivisible parts of our language.
REFER TO SLIDES
What is the notation of grammar - non-terminal symbols?
The things between angle brackets are called non-terminal symbols
- The above grammar contains five rules (also called productions)
- In the sorts of grammar we will consider, every rule is of the form: non-terminal “::=” sequence of terminals and non-terminals
REFER TO SLIDES
What is the general structure of grammar?
When we specify a grammar, there will normally be a start symbol representing the “top level” of whatever construct we’re specifying.
REFER TO SLIDES
What are other symbols we can add?
We can also insert on the RHS the following symbols, between or after terminals and non-terminals:
- bars to indicate “or” (alternatives)
- an asterisk (called the “Kleene star”) to indicate “zero or more of the preceding thing”
- a plus sign to indicate “one or more of the preceding thing”
- a range of numbers (e.g. “3–4”) to indicate a number of possible instances of the preceding thing.
REFER TO SLIDES
What is BNF Coverage Criteria?
Once we have written a grammar to model our system
- If we’re developing tests based on syntax . . .
- The most straightforward coverage criterion is: use every terminal and every production rule at least once
- This includes:
○ Terminal Symbol coverage
○ Production coverage
○ Derivation coverage
But except in special cases, this will be impractical
REFER TO SLIDES FOR EXAMPLES
What is Terminal Symbol coverage (TSC)?
Test requirements contain each terminal symbol t in the grammar G.
REFER TO SLIDES FOR EXAMPLES
What is Production coverage?
Test requirements contain each production p in the grammar G.
- Production coverage subsumes terminal symbol coverage; if we’ve used every production, we’ve also used every terminal.
- (Since every terminal must be part of some production.)
REFER TO SLIDES FOR EXAMPLES
What is Derivation coverage?
Test requirements contain every possible string that can be derived from grammar G.
REFER TO SLIDES FOR EXAMPLES
Why do we need syntax based testing?
Much of the software we rely on makes use of grammars (though not always explicitly).
- For very simple programs, we might analyse the arguments “by hand”.
- For complex programs – we typically use a command-line argument parser to work out whether a user has supplied a valid set of arguments (and what we should do with them).
Whenever we validate entries into web forms or databases, we are often are defining a syntax to do so.
Application areas for syntax based testing - What are command lines?
Command-line programs often take arguments – sometimes adhering to very complex rules
- The syntax of command line apps can be defined by a grammar
Application areas for syntax based testing - What is Input Syntax?
Grammars are used to define whether something is a valid
- phone number
- postcode
- URL
- HTML page
- email address
- and many other formats.
Application areas for syntax based testing - What are domain specific languages?
Often, grammars will be useful to define what are called “domain-specific languages” (DSLs) which describe entities in a domain and things to do with them – e.g. Makefiles are an example of this.
- Syntaxes are typically used to define such languages.