Automated Testing of Software Components Based On Algebraic Specifications
Automated Testing of Software Components Based On Algebraic Specifications
1
Outline
Background
Motivation
Relatedworks
Aug./Sept. 2008
Algebriac Testing 2
Challenges in testing components
Components often have no user interface
Developers spend as much time in writing test harness
excessive overhead, inadequacy of testing, low effectiveness
Components are usually delivered as executable code
Aug./Sept. 2008
Algebriac Testing 3
Algebraic specification
A signature: Spec NAT
Sorts: nat;
a set of sorts and Operators:
a set of operators zero: -> nat;
Aug./Sept. 2008
Algebriac Testing 4
Basic idea of algebraic testing
By substituting constants
into variables, we can
generate test cases
S: stack, n: integer,
Aug./Sept. 2008
S.push(n).height() = S.height()+1
Algebriac Testing 5
Related works
Entities Result
Work /System Test case generation
tested checking
DAISTS Manually scripted ground terms Manual
ADT
Gonnon et al. 1981 substituted into axioms program
Aug./Sept. 2008
Algebriac Testing 6
Overview of the proposed approach
Sorts to represent all types of software entities:
ADT, Class, Component
Test case generation:
Aug./Sept. 2008
Algebriac Testing 7
CASOCC specification language
Spec Stack axioms
observable F; 1: create(x).getId() = x;
import Int, String; 2: findByPrimaryKey(x).getId() = x;
operations 3: create(x).height() = 0;
creator 4: S.push(n) = S;
Aug./Sept. 2008
Algebriac Testing 8
Behavioural semantics and observable sorts
Definition 1. (Observable sort)
In an AS <S, E>, a sort s is an observable sort implies
that there is an operation _ == _ : ssBool such that
for all ground terms t and t of sort s,
Aug./Sept. 2008
Algebriac Testing 9
Well founded formal specifications
Let U be a set of specification units in CASOCC and S
be a set of sorts. For each sort sS, there is a unit UsU
that specifies the software entity corresponding to sort s.
Let be the importation relation on S.
Aug./Sept. 2008
Algebriac Testing 10
Well-structured formal specifications
Definition 3. (Well structured specifications)
A specification U in CASOCC is well structured if it
satisfies the following conditions.
(1) It is well founded;
Aug./Sept. 2008
Algebriac Testing 11
Observation context
Definition 1. (Observation context)
A context of a sort c is a term C with one occurrence
of a special variable of sort c. The value of a term t of
sort c in the context of C, written as C[t], is the term
Aug./Sept. 2008
Algebriac Testing 12
Form of observation context
The general form of an observation context oc:
_.f1(...).f2(...).....fk(...).obs(...)
where
Aug./Sept. 2008
Algebriac Testing 13
Checkable test cases written T1=T2, [if C]
Test cases:
a test case is a triple <T1, T2, C>, where
T1 and T2 are ground terms
C (optional) is a ground term of Boolean sort.
Aug./Sept. 2008
Algebriac Testing 14
Test case generation algorithm (Skeleton)
Input:
Spec s: CASOCC specification unit of the main sort;
Sigs s1, s2, , sk: The signature of imported sorts;
TC: A subset of axioms in s (* the axioms to be tested *);
vc: Integer (*complexity upper bound of variables*);
oc: Integer (*complexity upper bound of observation contexts*) ;
Aug./Sept. 2008
Algebriac Testing 15
Properties of the test case generation algorithm
Theorem 1. The test case generation algorithm will always
terminate if the specification is well founded.
Theorem 2. The test cases generated are checkable, i.e. for all test
cases <t1=t2; if c> generated by the algorithm, t1, t2 and c are of
primitive or observable sorts.
Aug./Sept. 2008
Theorem 3. The test cases are valid. That is, if the specification is
well-structured and the observable sorts satisfy the constraints in
Definition 1, we have the following properties.
(a) The program correctly implements the specification with respect
to the behavioural semantics of algebraic specifications implies that
the evaluation of t1 and t2 using the program give equivalent results
provided that c is evaluated to be true.
(b) If the evaluation of t1 and t2 gives non-equivalent values in an
implementation when c is evaluated to true, then there are faults in
the program.
Algebriac Testing 16
Testing tool CASCAT
Algebriac Testing 17
Aug./Sept. 2008
Algebriac Testing 18
Experiment 1: Evaluation of effectiveness
The experiment process
Selection of subject components:
from well established public sources.
Development of formal specification:
based on the document and source code.
Aug./Sept. 2008
Algebriac Testing 19
The subjects: 1) Single Component Subjects
Subject/Component #C #M #L Src Type
Algebriac Testing 20
The subjects: 1) Multiple Components Subjects
Subject/Component #C #M #L Src Type
LinkedList 33 33 32 97.0
Math 98 73 73 100.0
Multiple component subjects
Course 24 24 14 58.3
College
Student 25 25 15 60.0
Customer 40 40 27 67.5
Sales Order 57 53 34 64.2
SalesRep 24 24 14 58.3
StorageBin 46 44 27 61.4
Warehouse
Widget 34 28 20 71.4
Gangster 9 8 8 100.0
Gangster
ReadAhead 35 33 31 93.9
RateTable 48 36 36 100.0
SafeDriver
RateQuote 272 220 202 91.8
#Mutants
Aug./Sept. 2008
250
Average rate
200 Rate
150
100
50
0
Cu ea d
W i st
ke t
ote
ag k
er
St p
t
Co k
r
Sa rse
t
Lin e n
Ra eBin
Ga art
b le
r
Ra ath
un
uc
ste
St Ba n
Re id ge
Re
de
oc
dL
m
ud
Qu
C
Ta
od
Co
Ah
M
Or
St
ng
sto
les
Pr
ad
te
te
or
Algebriac Testing 23
Main findings (2)
The fault detecting ability decreases only slightly when
testing multiple component subjects.
100
86.7
90 80.0
82.9 Single component
Aug./Sept. 2008
75.3
80
Multiple compoentns
70
60
50
40
30
17.9 17.3
20
10
0
Total Average Detecting Rate Sdt Dev
Algebriac Testing 24
Main findings (3)
The method consistently detects significantly more faults in
session beans than in BMP entities beans despite that entity
beans are usually much less complex than session beans.
100
91.04 86.71
BMP Entity Beans
90
Aug./Sept. 2008
80 Session Beans
70 64.02 64.13
60
50
40
30
20
10
0
Total Average
Cart 2 2 2 4 50m
Count 1 0 1 1 35m
Course 2 1 2 6 50m
Customer 2 2 3 4 60m
Gangster 2 5 20 19 90m
GeneralInfo 1 0 1 1 30m
LinkedList 1 2 5 16 100m
Math 1 1 5 9 60m
Order 2 0 5 5 60m
Product 2 3 10 14 70m
RateQuote 1 0 4 4 50m
RateTable 2 7 7 14 80m
ReadAhead 1 0 6 6 75m
Register 2 8 9 17 90m
SalesRep 2 1 2 3 40m
Stock 2 1 2 5 65m
StorageBin 3 0 2 4 40m
Student 2 1 2 4 40m
Widget 2 0 2 4 50m
Algebriac Testing 27
How to write algebraic specifications (1)
the description of the signature
the identification of the operations, e.g.
The signature of the operations can be derived from the type definitions of the
methods given in the source code.
the classification of operations
Aug./Sept. 2008
Creators: create instances of the software entity and/or initialise the entity.
They must have no parameters of the main sort, but result in the main sort.
Constructors: construct the data structure by adding more elements to the
data. A constructor must have a parameter of the main sort and results in the
main sort. It may occur in the normal forms if the axioms are used as term
rewriting rules.
Transformers: manipulate the data structure without adding more data.
Similar to constructors, a transformer must have the main sort as its parameter
and results in the main sort. However, it cannot occur in any normal forms.
Observers: enable the internal states or data in the software entity to be
observed from the outside. Observers must have a parameter of the main sort
but result in an imported sort.
Algebriac Testing 28
How to write algebraic specifications (2)
the determination of the axioms
For each setter setX(v) (set the value of attribute X to v),
s,v. (s.setX(v).getX = v), If pre-condsetX(v)
s,v. (s.setX(v).getY = s.getY),
where X Y.
Aug./Sept. 2008
Algebriac Testing 29
Experiment 2: Cost of writing algebraic spec
Subjects:
Students of computer science (35, year 3)
Mathematics course: Advanced University Mathematics Part A and Part
B and Discrete Mathematics.
Programming courses: C++ Programming, Java Programming and Data
Aug./Sept. 2008
Structure
No exposure to formal methods
Algebriac Testing 30
Distribution of capabilities
Aug./Sept. 2008
Algebriac Testing 31
Math Courses Prog Courses All Courses
Average 76.44 74.59 75.51
StDev 9.67 7.34 7.83
Aug./Sept. 2008
Algebriac Testing 32
Process of the experiment
Lesson 0:
Introduction to formal methods.
Lesson 1:
Introduced to algebraic specification and the CASOCC specification language.
An example formal specification of stacks
A brief introduction to software component for the first class test
Aug./Sept. 2008
Algebriac Testing 33
Marking scheme of class tests
Correctness of the answer: 50%.
Itis assess according to the correctness of the
signature and axioms in the students work.
Minor syntax errors that can be detected by
Aug./Sept. 2008
Algebriac Testing 34
Recording times
The time that each student took to complete the
class test was recorded in the experiment.
The students were given no limit on the time to
Aug./Sept. 2008
[1] , Java2007.
[2] Bodoff, S. et al. 2004. The J2EE Tutorial, 2nd Edt., Pearson 2004.
Algebriac Testing 36
Main Findings 1
Is writing algebraic specifications learnable?
Aug./Sept. 2008
Algebriac Testing 37
Changes in the distributions of scores
Aug./Sept. 2008
Algebriac Testing 38
Distributions of Grades in Class Tests
Grade Average Test 1 Test 2 Test 3 Test 4
A 8 1 25 31 33
B+ 23 0 4 2 0
Aug./Sept. 2008
B 4 3 5 2 2
C 0 20 0 0 0
F 0 11 1 0 0
The students learning experience is not hard. They
attained the knowledge and skill of algebraic specification in
just a few lessons.
Algebriac Testing 39
Main Findings 2
How expensive to write an algebraic specification for a
software component?
Aug./Sept. 2008
Algebriac Testing 40
Changes in the distributions of times
Aug./Sept. 2008
Algebriac Testing 42
Cluster analysis
We divide the students into the following four groups and
calculated their scores in class tests.
P>M: More capable of programming than mathematics.
P<M: More capable in mathematics than programming
Aug./Sept. 2008
Algebriac Testing 43
The students performances in class tests are
more closely related to their programming
capability than to mathematics knowledge and
skills.
Aug./Sept. 2008
Notes:
the link between students performance in class
tests and programming capability should be
interpreted as their capability of learning algebraic
specification rather than their final attainment.
the link is not strong since the absolute values of
the correlation coefficients are in the range from
0.41 to 0.52.
Algebriac Testing 44
Main Findings 4
Is writing algebraic formal specifications a job
only for the most capable?
Aug./Sept. 2008
Algebriac Testing 45
Aug./Sept. 2008
Algebriac Testing 47
(a) Relationship between final class test score and programming
capability
y = -0.0002x2 - 0.0148x + 98.405 (3)
Aug./Sept. 2008
After taking three lessons and class tests, the students are
capable of writing algebraic specifications of almost equal
quality, but the most capable ones took slightly less time.
Algebriac Testing 48
General conclusions of experiment 2
Conclusion 1 (Learnability): Writing algebraic specification is
learnable for ordinary software developers.
Conclusion 2 (Independence of mathematical skills) The
knowledge and skill of programming is more important than
Aug./Sept. 2008
Algebriac Testing 49
Limitations of the conclusions 1
The conclusions are only applicable to writing algebraic
formal specifications.
They do not necessarily imply that writing formal specifications
in other formalisms has the same properties.
Aug./Sept. 2008
Algebriac Testing 50
Limitations of the conclusions 2
The conclusions are only applicable to writing
formal specification
They do not necessarily imply that other formal
Aug./Sept. 2008
Algebriac Testing 51
Conclusion
Summary:
A technique of automated component testing based on algebraic
specifications.
A specification language CASOCC
An algorithm to generate checkable test cases.
Aug./Sept. 2008
Algebriac Testing 52
Future work
More experiments with multiple components
subjects
Extending the tool from testing EJB 2.0
Aug./Sept. 2008
Algebriac Testing 53
References
Gonnon, J., McMullin, P. and Hamlet, R., Data-Abstraction
Implementation, Specification and Testing, ACM TOPLAS 3(3),
1981, 211-223.
Bernot, G., Gaudel, M. C., and Marre, B., Software testing based on
formal specifications: a theory and a tool, Software Engineering
Aug./Sept. 2008
Algebriac Testing 54
Kong, L., Zhu, H., and Zhou, B. 2007.
Automated Testing EJB Components Based on
Algebraic Specifications. Proc. of
Aug./Sept. 2008
Algebriac Testing 55