Model Based Testing and Runtime Verification Flashcards
The behaviors allowed by the implementations
The behaviors allowed by the implementations are a subset of those allowed by the specification.
The Testing Perspective
Test -> Implementation -> Oracle
The Runtime Verification Perspective
User -> Implementation -> Monitor
Monitors
require generalization, making things harder. Hence we need a specification language (other than the programming language itself).
A Specification Language - Finite State Automata
Make a list of the inputs
For each input, note the situations in which the input can be applied and when it can’t
For each situation, note further situations when the input causes different behaviors
What variables do we need to model all possible situations
Runtime Verification
Basically monitoring the system under test through an RV tool.
RV architecture
Monitoring guarantees that the system never advances beyond failure.
Upon failure one can attempt to fix the problem since we are guaranteed to stop immediately after the failure.
The cost in overheads can be prohibitive if the volume of monitored events is large.
The system can break real-time properties because of monitor-caused delays.
Building the Architecture
Separate specification from system requirements, this requires additional work to weave the two together.
Separation of Concerns: Aspect-Oriented Programming
Modular abstraction techniques (OO design aims at abstracting models, sharing common parts across the implementation).
Sometimes, one modularization strategy forgoes another, requiring code replication and the merging of business logic and support code.
Aspect-Oriented programming gives ways of changing code across a whole system in a modular way.
Consider adding a logging feature for all types of money transfers, which can be toggled on or off; by adding a line to each transfer method or by using an AOP tool.
Property Specification Languages: Automata
Finite State Automata can be a good way of allowing the specification of consequentiality behavior. Access to system data enhances expressiveness and interaction with the system.
Parameterization allows us to have a separate monitor per use.
Determinism
Monitoring automata should be deterministic. Transitions and automata are ordered.
RV Tool
Larva - used in JAVA using Symbolic Timed Automata.
Property Specifications
DATEs (Dynamic Automata with Timers and events): Automata based. Dynamic creation of new properties (automata). Replication of properties per object instance. Triggering of transitions based on program method invocations, program exceptions, real time events, and channel communication between automata.
Model Based Testing
Testing is mainly done manually which is tedious and error prone, automation is better.
Bugs occur at the model and implementation. We can check correspondence to find bugs.
Generic Model Based Testing
Test suite generation: Use the model to generate meaningful inputs/sequences of inputs (Decide the strategy of traversing the model).
Prioritizing Test Cases: Random, Greedy Algorithm, Lookahead.
Executing Tests: Usually automated but might need some scaffolding/adapter.
Test Suite Execution
Offline: Generate once, execute many times (ex. Regression Testing)
Online: Generate on-the-fly, Ideal for time-bound testing (ex. Test for a whole night). Testing systems whose environment cannot be easily simulated (such as 3rd party systems).
Oracle Problem
Models necessitate automation of oracle since model based testing is usually very fast and comprehensive (in terms of system functionality). Ex. Assertions can be added to FSMs to check the system still corresponds with the model.
Measuring Test Effectiveness
Structural Code Coverage - Aims to exercise code or model concerning some coverage goal.
Coverage Measures:
States visited
Transitions visited
Transition pair combinations
Test Failures
Fix the models because it isn’t correct
Fix the system because it isn’t correct
JUNIT Model
Define a model
Normally using an FSM with variables, conditions and actions
Build graph of possible transitions
Generates abstract teszta.
- Add operation on SUT
- Update any tracked variables
- Add JUNIT assertions on SUT after applying actions
Guards
You can add a guard to indicate when it is possible to choose a particular action. Add a method that returns a Boolean. It should have the same name as the action method name and end with the word Guard.
Generating Test Cases
- Random
- Greedy Tester: Decides at the current state which transitions are yet to be visited
- Lookahead tester: Looks ahead to find unvisited transitions