patrick lam university of waterloo october 3, 2015 · and custom classloaders. 15/77. dependent...

77
Static and Dynamic Analysis of Test Suites Patrick Lam University of Waterloo October 3, 2015 1 / 77

Upload: others

Post on 13-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Static and Dynamic Analysis of Test Suites

Patrick LamUniversity of Waterloo

October 3, 2015

1 / 77

Page 2: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Goal

Convince you toanalyze tests (with their programs).

2 / 77

Page 3: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Why do we analyze programs?

3 / 77

Page 4: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Motivations for Program Analysis

enable program understanding &transformation;

eliminate bugs;ensure software quality.

4 / 77

Page 5: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Observation

Programs come with gobs of tests.

5 / 77

Page 6: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Pervasiveness of Test Suites

m=0.3002

m=0.03514

6 / 77

Page 7: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Tests and Modern Software

Extensive library support:

7 / 77

Page 8: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

What Tests Do

Tests encode:how to invoke the system under test; and,what it should do.

8 / 77

Page 9: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Opportunity

Leverage test suites in program analysis.

9 / 77

Page 10: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Related Work

10 / 77

Page 11: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Static Analysis Limitations

11 / 77

Page 12: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Dynamic Analysis Limitations

12 / 77

Page 13: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Concolic analysis

Run the program with arbitrary inputs,(some symbolic);

use solver to find new paths/inputs.

13 / 77

Page 14: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

PHP Analysis (Kneuss, Suter, Kuncak)

Choose program inputs and run the program.Observe the configuration loading phase.Use configuration information to do type analysison the remainder of the program.

14 / 77

Page 15: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

TamiFlex (Bodden et al)

Choose program inputs and run theprogram.Observe classes loaded through reflection

and custom classloaders.

15 / 77

Page 16: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Dependent Array Type Inference from Tests (Zhu,Nori & Jagannathan)

Goal: learn quantified array invariants.

Approach: observe from test runs; namely:guess coarse templates;run with simple random tests;generate constraints;validate types.

16 / 77

Page 17: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

DSD-Crasher (Csallner and Smaragdakis)

17 / 77

Page 18: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Empirical Studies

18 / 77

Page 19: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Complexity of Test Suites

19 / 77

Page 20: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

% Tests with control-flow

20 / 77

Page 21: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Similar Test Methods(a case study in static analysis of tests)

(with Felix Fang)

21 / 77

Page 22: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Story: Writing Widget class

By Joonspoon (Own work) [CC BY-SA 4.0 (http://creativecommons.org/licenses/by-sa/4.0)], via Wikimedia Commons22 / 77

Page 23: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Story: Writing Widget class

1 class FooWidget extendsWidget {

2 /*...*/

3 }4

5 class BarWidget extendsWidget {

6 /*...*/

7 }

1 @Test2 class FooWidgetTest {3 /*...*/

4 }5

6 @Test7 class BarWidgetTest {8 /*...*/

9 }

23 / 77

Page 24: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Story: Writing New Code

1 class BazWidget extendsWidget {

2 /* New Code */

3 }

1 @Test2 class BazWidgetTest {3 /* ? */

4 }

24 / 77

Page 25: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Story: Writing New Code

1 class BazWidget extendsWidget {

2 /* New Code */

3 }

1 @Test2 class BazWidgetTest {3 /* Ctrl-C, Ctrl-V */

4 }

25 / 77

Page 26: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Hypothesis

Developers often copy-paste tests(and probably enjoy doing it).

Why? JUnit test cases tend to be self-contained.

Test clones can become difficult to comprehend ormaintain later.

26 / 77

Page 27: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Benefits of Refactoring Tests

xUnit Test Patterns: Refactoring Test Code(Meszaros)

Reduce long term maintenance cost (Saff)

Can detect new defects and increase branchcoverage if tests are parametrized(Thummalapenta et al)

Reduce brittleness and improve ease ofunderstanding

27 / 77

Page 28: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Refactoring Techniques

Language features such as inheritance orgenerics

Parametrized Unit Tests and Theories

28 / 77

Page 29: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Refactoring Example

1 public void testNominalFiltering() {2 m_Filter = getFilter(Attribute.NOMINAL);3 Instances result = useFilter();4 for (int i = 0; i < result.numAttributes(); i++)5 assertTrue(result.attribute(i).type() != Attribute.NOMINAL);6 }

1 public void testStringFiltering() {2 m_Filter = getFilter(Attribute.STRING);3 Instances result = useFilter();4 for (int i = 0; i < result.numAttributes(); i++)5 assertTrue(result.attribute(i).type() != Attribute.STRING);6 }

29 / 77

Page 30: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Refactored Example

1 static final int [] filteringTypes = {2 Attribute.NOMINAL, Attribute.STRING,3 Attribute.NUMERIC, Attribute.DATE4 };56 public void testFiltering() {7 for (int type : filteringTypes)8 testFiltering(type);9 }

1011 public void testFiltering(final int type) {12 m_Filter = getFilter(type);13 Instances result = useFilter();14 for (int i = 0; i < result.numAttributes(); i++)15 assertTrue(result.attribute(i).type() != type);16 }

30 / 77

Page 31: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Our Contributions

Test refactoring candidate detection techniqueusing Assertion Fingerprints

Empirical and qualitative analyses of results on 10Java benchmarks

31 / 77

Page 32: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

What is a test case made of?

Setup

Run/Exercise

Verify

Teardown

32 / 77

Page 33: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

What is a test case made of?

Setup

Run/Exercise

Verify

Teardown

33 / 77

Page 34: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Key Insight

Similar tests often have similar sets of asserts.

34 / 77

Page 35: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Similar Sets of Asserts: Example

1 public void test1() {2 /* ... */

3 assertEqual(int, int);4 /* ... */

5 assertEqual(float, float);6 /* ... */

7 assertTrue(boolean);8 }

1 public void test2() {2 /* ... */

3 assertEqual(int, int);4 /* ... */

5 assertEqual(float, float);6 /* ... */

7 assertTrue(boolean);8 }

35 / 77

Page 36: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Our Approach

Assertion Fingerprints

36 / 77

Page 37: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Assertion Fingerprints

Augment set of assertions.

For each assertion call, collect:

Parameter types

Control flow components

37 / 77

Page 38: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Using Assertion Fingerprints

Group tests with similar assert structures.

38 / 77

Page 39: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Assertion Fingerprints: Control Flow Components

Branch Count (Branch Vertices)

Merge Count (Merge Vertices)

In Loop Flag (Depth First Traversal)

Exceptional Successor Count (Exceptional CFG)

In Catch Block Flag (Dominator Analysis)

39 / 77

Page 40: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Example: Code

1 public void test() {2 int i;3 for (i = 0; i < 10; ++i) {4 if (i == 2)5 assertEquals(i, 2);6 assertTrue(i != 10);7 }8 try {9 throw new Exception();

10 fail("Should have thrown exception");11 } catch (final Exception e) {12 assertEquals(i, 10);13 }14 }

40 / 77

Page 41: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Example: CFG

/** line 3*/{i < 10}

start

/** line 4* bc:1 ({i<10})* inLoop:true*/{i == 2}

try:/** line 10* bc:1 (¬{i<10})* es:1*/fail(String)

/** line 5* bc:2 ({i<10},{i==2})* inLoop:true*/assertEquals(int, int)

/** line 6* bc:1 ({i<10})* mc:1 ({i==2})* inLoop:true*/{i != 10}catch:

/** line 12* bc:1 (¬{i<10})* inCatch:true*/assertEquals(int, int) /*

* line 6* bc:1 ({i<10})* mc:2 ({i==2},{i!=10})* inLoop:true*/assertTrue(boolean)

true

falsetrue

false

Exception

true false

41 / 77

Page 42: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Branch Count: Intuition

An assertion inside an if statement is likely to bedifferent from one that is not.

42 / 77

Page 43: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Example: CFG

/** line 3*/{i < 10}

start

/** line 4* bc:1 ({i<10})* inLoop:true*/{i == 2}

try:/** line 10* bc:1 (¬{i<10})* es:1*/fail(String)

/** line 5* bc:2 ({i<10},{i==2})* inLoop:true*/assertEquals(int, int)

/** line 6* bc:1 ({i<10})* mc:1 ({i==2})* inLoop:true*/{i != 10}catch:

/** line 12* bc:1 (¬{i<10})* inCatch:true*/assertEquals(int, int) /*

* line 6* bc:1 ({i<10})* mc:2 ({i==2},{i!=10})* inLoop:true*/assertTrue(boolean)

true

falsetrue

false

Exception

true false

43 / 77

Page 44: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Branch Count

Minimal number of branches needed to reach thatvertex from the start of a method, excluding n.

44 / 77

Page 45: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Merge Count: Intuition

An assertion with some prior operations inside anif statement is likely to be different from one thatis not with any.

45 / 77

Page 46: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Example: CFG

/** line 3*/{i < 10}

start

/** line 4* bc:1 ({i<10})* inLoop:true*/{i == 2}

try:/** line 10* bc:1 (¬{i<10})* es:1*/fail(String)

/** line 5* bc:2 ({i<10},{i==2})* inLoop:true*/assertEquals(int, int)

/** line 6* bc:1 ({i<10})* mc:1 ({i==2})* inLoop:true*/{i != 10}catch:

/** line 12* bc:1 (¬{i<10})* inCatch:true*/assertEquals(int, int) /*

* line 6* bc:1 ({i<10})* mc:2 ({i==2},{i!=10})* inLoop:true*/assertTrue(boolean)

true

falsetrue

false

Exception

true false

46 / 77

Page 47: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Merge Count

Minimal number of merge vertices needed toreach vertex n from the start of the method,including n.

47 / 77

Page 48: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

In-Loop Flag: Intuition

An assertion inside a loop is likely to be differentfrom one that is not.

48 / 77

Page 49: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Example: CFG

/** line 3*/{i < 10}

start

/** line 4* bc:1 ({i<10})* inLoop:true*/{i == 2}

try:/** line 10* bc:1 (¬{i<10})* es:1*/fail(String)

/** line 5* bc:2 ({i<10},{i==2})* inLoop:true*/assertEquals(int, int)

/** line 6* bc:1 ({i<10})* mc:1 ({i==2})* inLoop:true*/{i != 10}catch:

/** line 12* bc:1 (¬{i<10})* inCatch:true*/assertEquals(int, int) /*

* line 6* bc:1 ({i<10})* mc:2 ({i==2},{i!=10})* inLoop:true*/assertTrue(boolean)

true

falsetrue

false

Exception

true false

49 / 77

Page 50: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Exceptional Successors Count: Intuition

An assertion inside a try block with correspondingcatch block(s) is likely to be different from one thatis not.

50 / 77

Page 51: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Example: CFG

/** line 3*/{i < 10}

start

/** line 4* bc:1 ({i<10})* inLoop:true*/{i == 2}

try:/** line 10* bc:1 (¬{i<10})* es:1*/fail(String)

/** line 5* bc:2 ({i<10},{i==2})* inLoop:true*/assertEquals(int, int)

/** line 6* bc:1 ({i<10})* mc:1 ({i==2})* inLoop:true*/{i != 10}catch:

/** line 12* bc:1 (¬{i<10})* inCatch:true*/assertEquals(int, int) /*

* line 6* bc:1 ({i<10})* mc:2 ({i==2},{i!=10})* inLoop:true*/assertTrue(boolean)

true

falsetrue

false

Exception

true false

51 / 77

Page 52: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

In-Catch-Block Flag: Intuition

An assertion inside a catch block is likely to bedifferent from one that is not.

52 / 77

Page 53: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Example: CFG

/** line 3*/{i < 10}

start

/** line 4* bc:1 ({i<10})* inLoop:true*/{i == 2}

try:/** line 10* bc:1 (¬{i<10})* es:1*/fail(String)

/** line 5* bc:2 ({i<10},{i==2})* inLoop:true*/assertEquals(int, int)

/** line 6* bc:1 ({i<10})* mc:1 ({i==2})* inLoop:true*/{i != 10}catch:

/** line 12* bc:1 (¬{i<10})* inCatch:true*/assertEquals(int, int) /*

* line 6* bc:1 ({i<10})* mc:2 ({i==2},{i!=10})* inLoop:true*/assertTrue(boolean)

true

falsetrue

false

Exception

true false

53 / 77

Page 54: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Filtering: Must satisfy one of the following

Contain some control flow

Contain more than 4 assertions

Heterogeneous in signature(invoke different assertion types)

54 / 77

Page 55: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Evaluation: Implementation

@Test A()

@Test B()

@Test C()

Soot

CFG(A)

CFG(B)

CFG(C)

[fingerprint(A)]

[fingerprint(B)]

[fingerprint(C)]

55 / 77

Page 56: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Evaluation: Benchmarks

Test LOC Total LOC % Test LOCApache POI 86 113 247 799 35%Commons Collections 46 129 110 394 42%Google Visualization 13 440 31 416 43%HSQLDB 30 481 32 208 95%JDOM 25 618 76 734 33%JFreeChart 93 404 317 404 29%JGraphT 12 142 41 801 29%JMeter 20 260 182 293 11%Joda-Time 67 978 134 758 50%Weka 26 270 495 198 5%

56 / 77

Page 57: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Evaluation: Analysis Run Time (seconds)

Apache POI 113Commons Collections 50Google Visualization 240HSQLDB 233

JDOM 25JFreeChart 70JGraphT 43JMeter 70

Joda-Time 45Weka 91

Total 994

57 / 77

Page 58: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Results: Detected Refactoring Candidates

58 / 77

Page 59: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Results: Asserts vs Methods distribution

0 20 40 60 80

0

50

100

150

200

Asserts

Met

hods

59 / 77

Page 60: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Results: Sampling, 75% True Positive rate

60 / 77

Page 61: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Qualitative Analysis: JGraphT

Small and heterogenous tests that are unlikely tobe false positives

61 / 77

Page 62: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Qualitative Analysis: Joda-Time

Wide hierarchy of tests with identical structuresand straight-line assertions.

62 / 77

Page 63: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Qualitative Analysis: Weka, Apache CommonsCollections

Textually identical clones of methods with similardata types but with different environment setups.

63 / 77

Page 64: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Qualitative Analysis: JDOM

1 public void test_TCC___String() {2 // [... 4x assertTrue(String, boolean)]

3 try {4 // ...

5 fail("allowed creation of an element with no name");6 } catch (IllegalNameException e) {7 // Test passed!

8 }9 }

64 / 77

Page 65: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Qualitative Analysis: Google Visualization

Complex query-related statements and helpermethods reduce the roles of assertions in a testmethod, resulting in a below-average true positiverate.

65 / 77

Page 66: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Qualitative Analysis: Refactorability

Test methods that show structural similarities aremost likely amenable to refatoring, however;

Non-parametrized and small methods are diffcultto refactor.

66 / 77

Page 67: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Next Step

Guided test refactoring.

67 / 77

Page 68: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Future Perspectives

68 / 77

Page 69: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

What Do We Do With Tests?

Tradtionally:run the test, get yes/no answer.

(Also, can combine with DSD/concolicanalysis.)

69 / 77

Page 70: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Our usual interaction with tests (static)

ProgramTests

Analysis Tool

Generated Tests

Statically, we usually just ignore tests.

70 / 77

Page 71: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Our usual interaction with tests (dynamic)

Program

Tests

Analysis Tool

Generated Tests

Tests are write-only with respect to the tool.

71 / 77

Page 72: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

A Better Way

ProgramTests

Analysis Tool

Generated Tests

72 / 77

Page 73: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Why is it hard to write tests?

Need to:1 get system under test in appropriate state;2 decide what the right answer is.

Useful hints for static analysis!

73 / 77

Page 74: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Unit tests also illustrate. . .

interesting points in execution space, withcomplete execution environments

for program fragments.

74 / 77

Page 75: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Challenges

How to combine information from test runs?

What can we learn from failing tests?

75 / 77

Page 76: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Conclusions

76 / 77

Page 77: Patrick Lam University of Waterloo October 3, 2015 · and custom classloaders. 15/77. Dependent Array Type Inference from Tests (Zhu, Nori & Jagannathan) Goal: learn quantified array

Tests: An Opportunity for Program Analysis

We can go beyond test generation.

Tests are a valuable source of informationabout their associated programs.

77 / 77