Docsity

Automated Testing using Java Predicates: Korat Project, Study notes of Computer Science

Toggle sidebar
bg1
1
11/14/2003 1
Korat:
Automated Testing Based on
Java Predicates
Chandrasekhar Boyapati, Sarfraz
Khurshid, Darko Marinov
CSci 780 – Advanced Software
Engineering
11/14/2003 2
Outline
MulSaw Project
Problem
Example
Algorithm
Testing Methods
Results
TestEra, Alloy Analyzer, and others
Conclusions
Discussion
11/14/2003 3
MulSaw Project
MIT Students
Goal - design and implement tools for
checking
code conformance
Korat, TestEra, Alloy Annotation
Language(AAL)
MulSaw Web page
11/14/2003 4
Problem
Traditional Testing
Manual software testing
Test data generation
Labor Intensive
Software Engineering Utopia –
cheaper and better testing methods
11/14/2003 5
Proposed Solution
Automated Testing!
Reduce the cost of development and
maintenance
11/14/2003 6
General Idea behind Korat
Specification-based testing
Current prototype uses Java Modeling
Language(JML)
Method Precondition
Generate all nonisomorphic test cases
Execution
Method Postcondition
pf3
pf4
pf5

Partial preview of the text

Download Automated Testing using Java Predicates: Korat Project and more Study notes Computer Science in PDF only on Docsity!

11/14/2003 1

Korat:

Automated Testing Based on

Java Predicates

Chandrasekhar Boyapati, Sarfraz

Khurshid, Darko Marinov

CSci 780 – Advanced Software

Engineering

11/14/2003 2

Outline

„ MulSaw Project

„ Problem

„ Example

„ Algorithm

„ Testing Methods

„ Results

„ TestEra, Alloy Analyzer, and others

„ Conclusions

„ Discussion

11/14/2003 3

MulSaw Project

„ MIT Students

„ Goal - design and implement tools for

checkingcode conformance

„ Korat, TestEra, Alloy Annotation

Language(AAL)

„ MulSaw Web page

11/14/2003 4

Problem

„ Traditional Testing

„ Manual software testing

„ Test data generation

„ Labor Intensive

„ Software Engineering Utopia –

cheaper and better testing methods

Proposed Solution

„ Automated Testing!

„ Reduce the cost of development and

maintenance

General Idea behind Korat

„ Specification-based testing

„ Current prototype uses Java Modeling

Language(JML)

„ Method Precondition

„ Generate all nonisomorphic test cases

„ Execution

„ Method Postcondition

11/14/2003 7

Introductory Illustration

„ Method for removing the minimum

element from a balanced binary tree

„ Precondition – input is a binary tree and

it is balanced

„ Generate all balanced binary trees

„ Execute method on all cases

„ Postcondition

11/14/2003 8

Examples

11/14/2003 9

Examples

„ Binary Tree

„ Linked data structure

„ Heap Array

„ Array-based data structure

11/14/2003 10

Binary Tree example

class BinaryTree { private Node root; // root node private int size; //number of nodes in the tree static class Node { private Node left; // left child private Node right; // right child } public boolean repOk() { //class invariant } }

Binary Tree example(2)

„ Generate test cases – Finitization

„ Mostly generated automatically

public static Finitization finBinaryTree(int NUM_Node) { Finitization f = new Finitization(BinaryTree.class); ObjSet nodes = f.createObjects("Node", NUM_Node); // #Node = NUM_Node nodes.add(null); f.set("root", nodes); // root in null + Node f.set("size", NUM_Node); // size = NUM_Node f.set("Node.left", nodes); // Node.left in null + Node f.set("Node.right", nodes); // Node.right in null+ Node return f; }

Binary Tree example(3)

„ Finitization function generated all

nonisomorphic trees

„ finBinaryTree(3) – 5 trees

„ finBinaryTree(7) – 429 trees in < 1 sec

11/14/2003 19

Finitizationskeleton

„ Programmer can specialize the finitization to

meet certain criteria(in Java)

public static Finitization finBinaryTree(int NUM_Node, int MIN_size, int MAX_size) { Finitization f = new Finitization(BinaryTree.class); ObjSet nodes = f.createObjects("Node", NUM_Node); nodes.add(null); f.set("root", nodes); f.set("size", new IntSet(MIN_size, MAX_size)); f.set("Node.left", nodes); f.set("Node.right", nodes); return f; }

11/14/2003 20

State Space

„ Inspect state space for BinaryTree(3)

example

„ Specified objects from finitization:

„ One BinaryTree, three Nodes

„ Createscandidate vector

„ candidate vector for this example has 8

fields [root, size, 3*(left, right)]

11/14/2003 21

State Space(2)

„ State space of inputs is all possible

assignments to the fields

„ Possible values ofcandidate vector

= 4 * 1 * (4 * 4) 3 = 2 2 *(2^4 ) 3 = 2 14

11/14/2003 22

State Space(3)

„ Candidates can be valid…

State Space(4)

„ …or not valid

Search

„ Korat seeks to systematically explore

the state space

„ class and field domains are ordered in

thecandidate vector, such that each

entry is an index to the field domain

„ Initially all values are set to 0

11/14/2003 25

Search(2)

„ Korat sets the objects according to the

vector values

„ Executes repOk method on candidate

„ Records the fields accessed during

invocation of repOk()

„ Generates next vector through

backtracking (increments field that was

accessed last)

11/14/2003 26

Search(3)

„ Change only fields that were accessed

„ Prunes the search space dramatically

„ Does NOT rule out any valid data

structure

„ Quality of repOk method determines

extent of pruning

11/14/2003 27

Nonisomorphism

„ Further optimization of generation

process

„ Definition of isomorphism:

11/14/2003 28

Nonisomorphism(2)

„ What this means: isomorphism is

defined by the root object

„ Candidates partitioned by the

isomorphism criteria

„ Only the “smallest” from a partition is

generated

„ finBinaryTree(3) example – 1 tree

generated per every 3! distinct trees

Instrumentation

„ Korat adds a special constructor,

identifier field, and get and set methods

for any classes in the finitization

and repOk

Testing Methods

„ Generation of finitization for methods

„ Small amount of work left for user

„ When Korat cannot determine a field

automatically, inserts /****/. User must

replace this with the appropriate field

domain

11/14/2003 37

TestEra, Alloy, and others

„ Alloy – a declarative specification language

based on first order logic

„ Alloy Analyzer(AA) – a tool for analyzing

models written in Alloy, designed to do

similar things as Korat

„ Because of pruning and nonisomorphism,

Korat generates test cases much faster

than AA

„ TestEra – generates test cases from

specifications written in Alloy

11/14/2003 38

The Others

„ Static Analysis

„ Use a theorem prover to verify partial

correctness

„ Promising technique, but still limited

„ Model Checking

„ More focused on checking sequences

rather than data structures

11/14/2003 39

Conclusion

„ Korat can use preconditions to generate

test cases, execute a method on all test

cases, then use the postconditions as a

test oracle

„ Korat utilizes JML, which is very similar

to Java itself

„ Korat generates and tests much faster

than its buddy Alloy Analyzer

11/14/2003 40

Discussion

„ Is automated generation and testing the

wave of the future?

„ Are there downsides or limitations to this

method of testing?

„ Is Korat generating not enough or too many

test cases?

„ For the linked data structures, Korat

produced, at most, structures of size 12. Is

this domain large enough to test for

correctness?

11/14/2003 41

Future Work

„ Future research possibilities on the

MulSaw page:

„ http://mulsaw.lcs.mit.edu/projects.html