+ All Categories
Home > Documents > Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science...

Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science...

Date post: 06-Jan-2018
Category:
Upload: dennis-jackson
View: 216 times
Download: 0 times
Share this document with a friend
Description:
3 Contents Randomized unit testing Minimization Case study Experiment Related work
25
Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE 2005, 10 Nov 2005
Transcript
Page 1: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

Minimization of Randomized Unit Test Cases

Yong Lei, James H. AndrewsDept. of Computer Science Univ. Of Western OntarioLondon, Ontario, Canada

ISSRE 2005, 10 Nov 2005

Page 2: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

I apologize in advance for not being able to speak more loudly.

Page 3: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

3

Contents

• Randomized unit testing• Minimization• Case study• Experiment• Related work

Page 4: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

4

Unit Testing

• Testing methods, groups of methods, classes

• Key practice of TDD

Page 5: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

5

Conventional Unit Testing

• Write test cases (sequences of method calls)• Execute and verify each test case• Record % successes and failures

Page 6: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

6

Randomized Unit Testing

• Write test fragments• Execute many random sequences of

fragments• Keep failures, throw away successes• Potential: lots of automatically generated

test input, “unexpected” sequences

Page 7: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

7

Example Unit Under Test: “Course” Class

• Student object contains Courses taken• Course object contains prerequisite Courses• Course class contains addStudent method

– Succeeds (returning true) iff Student has taken all prerequisites

– Otherwise returns false

Page 8: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

8

Course: ConventionalUnit Testing

• Initialization: create Course c with prerequisites

• Test cases:– TC1: create Student with prerequisites; add to c– TC2: create Student with only some

prerequisites; try to add to c– TC3: create Student with no prerequisites; try

to add to c

Page 9: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

9

Course: Randomized Testing

• Initialization: create Course c, Student s• Test fragments:

– Add/delete random prerequisite from Course c– Add/delete random course taken from Student s– Try to add s to c

• Randomized test case = random sequence of test fragment calls

Page 10: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

10

Example Test Case

• addPrereq “cs 210”• addStudent• addTaken “cs 210”• addTaken “cs 212”• addPrereq “cs 211”• addStudent• …

Page 11: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

11

Randomized Unit Test Cases

• Testing engine can execute longer and longer randomized test cases

(TC2)

(TC1) (TC3)

(Failure)

Page 12: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

12

Previous Results

• TSE July 2003 paper: for lab-built units– Randomized testing covered more, was more

effective than thorough black-box test suite– Randomized testing more efficient than

effective black+white-box test suite• ASE 2004 paper: for Sourceforge units

– Building test fragments and driver reasonably fast

– Randomized testing effective

Page 13: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

13

Issue: Failing Test Case Length

• Randomized testing can find failing test cases

• These test cases tend to be long– Length = number of test fragments (“lines”)– Execute many irrelevant test fragments in

addition to ones on failing path• Long test cases difficult to use in debugging

Page 14: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

14

Solution: ddmin

• Can we apply Zeller & Hildebrandt’s ddmin algorithm to minimize them?

• How much smaller do they get?• What benefits do we obtain?• How efficient is the process?

Page 15: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

15

ddmin overview

• Start by cutting out large blocks, preserving failure

• Cut out smaller and smaller blocks, preserving failure

• Result: failing test case s.t. deleting any line will result in a successful test case

Page 16: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

16

Case Study: Sourceforge Units

• 3 faulty units with 2 faults each, 827 SLOC• Found 100 failing test cases for each; minimized

them• Example: htable.c fault 1

– Mean size of original failing test case: 51.69– Mean size of minimized test case: 5.12

• Average ratio minimized/original: 0.11• Average time to find and minimize: 1.8 CPU sec• Minimized test cases focused debugging

Page 17: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

17

Page 18: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

18

Experiment: Lab Data Structures

• 4 implementations of Dictionary ADT– Add, delete, find functions– Linked list, BST, AVL, B-tree impls– 681 NLOC

• 945 mutants (faulty versions) generated• Test fragment = 1 call to add, delete or find• Found 10 failing test cases for each;

minimized them

Page 19: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

19

Page 20: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

20

Page 21: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

21

Page 22: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

22

Page 23: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

23

Page 24: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

24

Page 25: Minimization of Randomized Unit Test Cases Yong Lei, James H. Andrews Dept. of Computer Science Univ. Of Western Ontario London, Ontario, Canada ISSRE.

25

Related Work

• Randomized testing: e.g. McKeeman• Jartege (Oriat)• Recent work on model checking +

randomized testing


Recommended