an introduction to search-based testing and the test ... · an introduction to search-based testing...

101
Gordon Fraser, University of Sheffield, UK Andrea Arcuri, Simula Research Labs, Norway Gordon Fraser, University of Sheffield An Introduction to Search-based Testing and the Test Generation Tool

Upload: others

Post on 21-Mar-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Gordon Fraser, University of Sheffield, UKAndrea Arcuri, Simula Research Labs, Norway

Gordon Fraser, University of Sheffield

An Introduction to Search-based Testing and the Test Generation Tool

Page 2: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Outline

1. What is Search Based Software Testing?

2. Building an SBST Tool is Easy!

3. Generating Unit Tests with EvoSuite

4. When to use and not to use EvoSuite

5. Extending EvoSuite

6. Ideas for future work in unit test generation

Page 3: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Outline

1. What is Search Based Software Testing?

2. Building an SBST Tool is Easy!

3. Generating Unit Tests with EvoSuite

4. When to use and not to use EvoSuite

5. Extending EvoSuite

6. Ideas for future work in unit test generation

Page 4: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Source code Tests

Automated test generation

Page 5: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software
Page 6: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software
Page 7: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Random Test Data Generation

Input

Page 8: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software
Page 9: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software
Page 10: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software
Page 11: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Generating vs CheckingConventional Software Testing Research

Write a method to construct test cases

Search-Based Testing

Write a method to determine how good a test case is

Page 12: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Generating vs CheckingConventional Software Testing Research

Write a method to construct test cases

Search-Based Testing

Write a fitness functionto determine how good a test case is

Page 13: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Fitness-guided search

Input

Fitn

ess

Page 14: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Fitness-guided search

Input

Fitn

ess

Page 15: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Search Operators

Components of an SBST Tool

Search Algorithm

Representation

Test ExecutionInstrumentationFitness Function

def testMe(x, y): if x == 2 * (y + 1): return True else: return False

Page 16: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Components of an SBST Tool

Meta-heuristic algorithm

Measure how good a candidate solution is

Execute tests

Search Algorithm

Representation

Search Operators

Test Execution

Instrumentation

Fitness Function

Encoding of the problem solution

Modifications of encoded solutions

Collect data/traces for fitness calculation during execution

Page 17: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software
Page 18: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software
Page 19: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software
Page 20: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Outline

1. What is Search Based Software Testing?

2. Building an SBST Tool is Easy!

3. Generating Unit Tests with EvoSuite

4. When to use and not to use EvoSuite

5. Extending EvoSuite

6. Ideas for future work in unit test generation

Page 21: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Outline

1. What is Search Based Software Testing?

2. Building an SBST Tool is Easy!

3. Generating Unit Tests with EvoSuite

4. When to use and not to use EvoSuite

5. Extending EvoSuite

6. Ideas for future work in unit test generation

Page 22: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

def testMe(x, y): if x == 2 * (y + 1): return True else: return False

Page 23: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Components of an SBST Tool

Hill-climbingSearch Algorithm

Representation

Search Operators

Test Execution

Instrumentation

Fitness Function

Page 24: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Hill Climbing

1. Select RandomValue

Page 25: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Hill Climbing

2. Explore Neighbourhood

Page 26: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Hill Climbing

3. Choose better neighbour

Page 27: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Hill Climbing

4. Repeat until optimum is found

Page 28: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Components of an SBST Tool

Hill-climbingSearch Algorithm

Representation

Search Operators

Test Execution

Instrumentation

Fitness Function

Page 29: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

(x, y) (x+1, y)(x-1, y)

(x-1, y+1) (x, y+1) (x+1, y+1)

(x-1, y-1) (x, y-1) (x+1, y-1)

def testMe(x, y): if x == 2 * (y + 1): return True else: return False

Page 30: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Components of an SBST Tool

Hill-climbingSearch Algorithm

Representation

Search Operators

Test Execution

Instrumentation

Fitness Function

Tuple (x, y)

Neighbourhood of (x, y)

Page 31: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Components of an SBST Tool

Hill-climbingSearch Algorithm

Representation

Search Operators

Test Execution

Instrumentation

Fitness Function

Tuple (x, y)

Neighbourhood of (x, y)

Page 32: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

SUTInput Output

Page 33: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

SUTInstrumentedSUT

Input

Output

Trace} FitnessTest Data

Page 34: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

def testMe(x, y): if x == 2 * (y + 1): return True else: return False

Page 35: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Components of an SBST Tool

Branch distance

Call method

Search Algorithm

Representation

Search Operators

Test Execution

Instrumentation

Fitness Function

Global variable

Hill-climbing

Tuple (x, y)

Neighbourhood of (x, y)

Page 36: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

100 1 2 3 4 5 6 7 8 9

9

0

1

2

3

4

5

6

7

8

Input Value

Fitne

ss

Page 37: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

9

0

1

2

3

4

5

6

7

8

Input Value

Fitne

ss

-(231) 231-10

Page 38: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

9

0

1

2

3

4

5

6

7

8

Input Value

Fitne

ss

-(231) 231-10

Page 39: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

9

0

1

2

3

4

5

6

7

8

Input Value

Fitne

ss

-(231) 231-10

Page 40: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Evolutionary Testing

Mutation

Crossover

Selection

Insertion

Fitness Evaluation

End?

Test cases

Monitoring

Execution

Page 41: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software
Page 42: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Crossover

a b c10 10 20 40

d

a b c20 -5 80 80

d

c80 80

d

a20

b-5

a10

b10

c20 40

d

Page 43: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

d40

Mutation

a b c10 10 20 20

d40

da20

Page 44: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

• Selective pressure: The higher, the more likely the fittest are chosen

• Stagnation: Selective pressure too small

• Premature convergence:Selective pressure too high

• Standard algorithms: Rank selection, tournament selection, roulette wheel selection

Selection

Page 45: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Outline

1. What is Search Based Software Testing?

2. Building an SBST Tool is Easy!

3. Generating Unit Tests with EvoSuite

4. When to use and not to use EvoSuite

5. Extending EvoSuite

6. Ideas for future work in unit test generation

Page 46: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Outline

1. What is Search Based Software Testing?

2. Building an SBST Tool is Easy!

3. Generating Unit Tests with EvoSuite

4. When to use and not to use EvoSuite

5. Extending EvoSuite

6. Ideas for future work in unit test generation

Page 47: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

@Test

public void test() {

}

int x = 2;int y = 2;int result = x + y;assertEquals(4, result);

Page 48: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

@Test

public void test() {

}

DateTime var3 = var1.toDateTime(var2);

DateTime var4 = var3.minus(var0);

TimeOfDay var2 = new TimeOfDay();

YearMonthDay var1 = new YearMonthDay(var0);

int var0 = 10

DateTime var5 = var4.plusSeconds(var0);

Page 49: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

DateTime var3 = var1.toDateTime(var2);

DateTime var4 = var3.minus(var0);

TimeOfDay var2 = new TimeOfDay();

YearMonthDay var1 = new YearMonthDay(var0);

int var0 = 10

DateTime var5 = var4.plusSeconds(var0);

Page 50: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software
Page 51: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Crossover

Page 52: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Mutation

Page 53: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Mutation

Page 54: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Fitness

public int gcd(int x, int y) { int tmp; while (y != 0) { tmp = x % y; x = y; y = tmp; } return x;}

Page 55: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Components of an SBST Tool

Sum of branch distances (and others)

Java reflection

Search Algorithm

Representation

Search Operators

Test Execution

Instrumentation

Fitness Function

Java bytecode instrumentation

Genetic Algorithm (+Archive, Seeding, Local Search, DSE)

Sets of sequences of Java statements

Standard GA operators implemented for test suites

Page 56: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Stats

• 6,865 commits

• 229,889 LOC

• 2,420 tests

Page 57: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

AcknowledgementsAndrea ArcuriJosé CamposBenjamin FriedrichFlorian GrossJuan Pablo GaleottiAlessandra GorlaMat HallFitsum Meshesha KifitewMerlin LangYanchuan LiEva MayPhil McMinn

Andre MisDaniel MuthAnnibale PanichellaDavid PatersonJeremias RoesslerJose Miguel RojasKaloyan RusevSina ShamshiriSebastian SteenbuckAndrey TarasevichMattia VivantiThomas White

Page 58: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Does it work?

Bugs

foun

d

0%

25%

50%

75%

100%

JFreeChart Closure Math Lang Joda Time0

0.1

0.2

0.3

0.4

10% 20% 30% 40% 50% 60% 70% 80% 90% 100%

Defects4J: 357 real bugsSF110: 23,886 Classes6,628,619 LOC

G. Fraser, A. Arcuri. “A Large Scale Evaluation of Automated Unit Test Generation with EvoSuite” TOSEM 24(2), 2014.

Shamshiri et al. "Do Automatically Generated Unit Tests Find Real Faults? An Empirical Study of Effectiveness and Challenges” ASE, 2015

Page 59: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Coverage

0

25

50

75

100

Option Rational DocType ArrayIntList

EvoSuite Manual

G. Fraser et al. "Does automated unit test generation really help software testers? A controlled empirical study." TOSEM, 2015

Page 60: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Time Spent on Testing

0

6.5

13

19.5

26

FilterIterator FixedOrderComparator ListPopulation PredicatedMap

Assisted Manual

J. Rojas et al. "Automated unit test generation during software development: A controlled experiment and think-aloud observations." , ISSTA 2015

Page 61: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Fault Detection

0

0.5

1

1.5

2

Option Rational DocType ArrayIntList

EvoSuite Manual

G. Fraser et al. "Does automated unit test generation really help software testers? A controlled empirical study." TOSEM, 2015

Page 62: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Faults Prevention

0

4

8

12

16

FilterIterator FixedOrderComparator ListPopulation PredicatedMap

Assisted Manual

J. Rojas et al. "Automated unit test generation during software development: A controlled experiment and think-aloud observations." , ISSTA 2015

Page 63: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Time Spent UnderstandingT

ime

(min

)

0

1.75

3.5

5.25

7

StdXMLR

eade

r

Attribu

te

ChainB

ase

Opt

ion

Fixed

Ord

erCom

para

tor

Filter

ListIt

erato

r

Plugin

Rules

RulesB

ase

CharR

ange

Year

Month

Day

Default Optimised

Page 64: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Method Names

@Test(timeout = 4000) public void testFooReturningFalse() throws Throwable { StringExample stringExample0 = new StringExample(); boolean boolean0 = stringExample0.foo(""); assertFalse(boolean0); }

@Test(timeout = 4000) public void test3() throws Throwable { StringExample stringExample0 = new StringExample(); boolean boolean0 = stringExample0.foo(""); assertFalse(boolean0); }

Page 65: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Variable Names @Test(timeout = 4000) public void testFooReturningFalse() throws Throwable { StringExample stringExample0 = new StringExample(); boolean boolean0 = stringExample0.foo(""); assertFalse(boolean0); }

@Test(timeout = 4000) public void testFooReturningFalse() throws Throwable { StringExample invokesFoo = new StringExample(); boolean resultFromFoo = invokesFoo.foo(""); assertFalse(resultFromFoo); }

Page 66: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Variable Namespublic class Foo { public void foo() { StringExample sx = new StringExample(); boolean bar = sx.foo(""); }}

@Test(timeout = 4000) public void testFooReturningFalse() throws Throwable { StringExample sx = new StringExample(); boolean bar = sx.foo(""); assertFalse(bar); }

Page 67: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Getting EvoSuite

http://www.evosuite.org/downloads

• Jar release - for command line usage

• Maven plugin

• IntelliJ plugin

• Eclipse plugin

• Jenkins plugin

Page 68: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Testing a Class

• Demo - command line

• Main options: -projectCP -class -criterion

Page 69: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Properties• -Dproperty=value

• Search budget (s) -Dsearch_budget=60

• Assertion generation-Dassertions=false -Dassertion_strategy=all

• Minimisation (length and values) -Dminimize=false

• Inlining-Dinline=false

Page 70: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

EvoSuite Sandbox

• Demo - Nondeterministic class

• Runtime library to execute tests

Page 71: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Testing multiple classes

Demo:

• Target / prefix

• Continuous

• Maven

• Jenkins

• IntelliJ

Page 72: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Outline

1. What is Search Based Software Testing?

2. Building an SBST Tool is Easy!

3. Generating Unit Tests with EvoSuite

4. When to use and not to use EvoSuite

5. Extending EvoSuite

6. Ideas for future work in unit test generation

Page 73: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Outline

1. What is Search Based Software Testing?

2. Building an SBST Tool is Easy!

3. Generating Unit Tests with EvoSuite

4. When to use and not to use EvoSuite

5. Extending EvoSuite

6. Ideas for future work in unit test generation

Page 74: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

When to use and not to use EvoSuite

• Should I use EvoSuite…

• …to test my own Java code?

• Yes, of course

Page 75: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

When to use and not to use EvoSuite

• Should I use EvoSuite…

• …to implement my ideas on unit test generation?

• Yes, of course

Page 76: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

When to use and not to use EvoSuite

• Should I use EvoSuite…

• …to study developer behaviour?

• Yes, of course

Page 77: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

When to use and not to use EvoSuite

• Should I use EvoSuite…

• …to generate unit tests for my experiment on X?

• Yes, of course

Page 78: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

When to use and not to use EvoSuite

• Should I use EvoSuite…

• …to build a unit test generator for a different programming language?

• EvoSuite is 90% JVM handling code

• Would need to reimplement representation, search operators, fitness functions, test execution, …

Page 79: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

When to use and not to use EvoSuite

• Should I use EvoSuite…

• …to create an Android testing tool?

• Android uses Java / Dalvik bytecode

• Can also compile to Java bytecode

• How to handle Android dependencies?

Page 80: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

When to use and not to use EvoSuite

• Should I use EvoSuite…

• …to create a GUI testing tool?

• If you want to test Java/Swing applications…

• But a GA may not be the right choice

Page 81: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

When to use and not to use EvoSuite

• Should I use EvoSuite…

• …to create a web app testing tool?

• If it’s based on JEE, unit testing already works (JEE support is not complete yet)

• System testing…see GUI testing

Page 82: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

When to use and not to use EvoSuite

• Should I use EvoSuite…

• …to implement a non-test generation SBSE tool?

• GA implementation is quite test specific

• Using for other purposes would need refactoringBut then, is it better than using existing generic GA libraries?

• If the tool uses Java, why not?

Page 83: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

When to use and not to use EvoSuite

• Should I use EvoSuite…

• …to implement a tool that requires tests?

• E.g., specification mining, fault localisation, program repair, GI, …

• Sure, integrating EvoSuite should be easy

Page 84: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Outline

1. What is Search Based Software Testing?

2. Building an SBST Tool is Easy!

3. Generating Unit Tests with EvoSuite

4. When to use and not to use EvoSuite

5. Extending EvoSuite

6. Ideas for future work in unit test generation

Page 85: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Outline

1. What is Search Based Software Testing?

2. Building an SBST Tool is Easy!

3. Generating Unit Tests with EvoSuite

4. When to use and not to use EvoSuite

5. Extending EvoSuite

6. Ideas for future work in unit test generation

Page 86: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Building EvoSuite

• Git repository: git clone https://github.com/EvoSuite/evosuite.git

• Mavenmvn package (mvn -DskipTests package)

• Where is EvoSuite now? master/target/evosuite-master-1.0.4-SNAPSHOT.jar

• Why is the jar file so huge?

Page 87: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Module Structure

• master

• client

• runtime

• standalone-runtime

• plugins

• generated

• shaded

Page 88: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Extending EvoSuite

• (Artificial) Example: Middle point crossover

Page 89: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Extending EvoSuite

• (Artificial) Example: Middle point crossover

Page 90: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Outline

1. What is Search Based Software Testing?

2. Building an SBST Tool is Easy!

3. Generating Unit Tests with EvoSuite

4. When to use and not to use EvoSuite

5. Extending EvoSuite

6. Ideas for future work

Page 91: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Outline

1. What is Search Based Software Testing?

2. Building an SBST Tool is Easy!

3. Generating Unit Tests with EvoSuite

4. When to use and not to use EvoSuite

5. Extending EvoSuite

6. Ideas for future work

Page 92: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

1. SBST is Slow

• Fitness evaluation means executing tests

• Executing tests is slow

• How to reduce the number of fitness evaluations?

• How to improve search operators?

• Can we use ML to predict test execution results?

Page 93: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

2. OO Guidance

• Object oriented code has a terrible search landscape

• Complex dependency objects are a problem

• Include dependency objects in fitness functions?

• Better testability transformations?

• Better fitness functions?

Page 94: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

3. New Features

• Integration testing

• Concurrent code

• GUI handling code

• Database dependent code

• Prioritising tests

Page 95: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

4. SBST Usability

• Assertion/contract testing code?

• Coverage isn’t a great objective

• Usability as optimisation goal

• Study developers using SBST tools

Page 96: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Outline

1. What is Search Based Software Testing?

2. Building an SBST Tool is Easy!

3. Generating Unit Tests with EvoSuite

4. When to use and not to use EvoSuite

5. Extending EvoSuite

6. Ideas for future work

Page 97: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Outline

1. What is Search Based Software Testing?

2. Building an SBST Tool is Easy!

3. Generating Unit Tests with EvoSuite

4. When to use and not to use EvoSuite

5. Extending EvoSuite

6. Ideas for future work

Page 98: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

Online Tutorials

• Using EvoSuite on the command line: http://www.evosuite.org/documentation/tutorial-part-1/

• Using EvoSuite with Maven: http://www.evosuite.org/documentation/tutorial-part-2/

• Running experiments with EvoSuite: http://www.evosuite.org/documentation/tutorial-part-3/

• Extending EvoSuite: http://www.evosuite.org/documentation/tutorial-part-4/

Page 99: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

2. Corner Cases

• Constant Seeding: +5%

• Virtual FS: +1.4%

• Mocking +4.7%

• JEE support: +3%

• DSE: +1.2%

Page 100: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

3. Developers

public class Example {

private Example() {}

// …}

Page 101: An Introduction to Search-based Testing and the Test ... · An Introduction to Search-based Testing ... to determine how good a test case is. Generating vs Checking Conventional Software

4. Testing

EvoSuite uses one central random number generator

Any change will affect something at a completely different part of the program

Change seeds frequently during testing to find flaky tests