34
Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

Embed Size (px)

Citation preview

Page 1: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

Feedback-Directed Random Test Generation

Automatic Testing & ValidationCSI5118

By Wan Bo

Page 2: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

Introduction

Page 3: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Random Testing VS System Testing

– No certain conclusion which is better

– Advantages of random testing for OO

– Normal random test generation is unguided.

Page 4: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Purpose of this work:

– random generation of unit tests for object-oriented programs.

– a sequence of method calls for unit test.

– random selecting or previous computed object as parameters for each method call.

Page 5: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Benefits of guided generation:– only sensible to build a legal sequence of method

calls– Speed up generate process and reduce redundant

sequences.– Example:• Double a = sqrt(-1);• Double b = log(a);• With feedback, such call sequence will not be

extended.

Page 6: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• RANDOOP- random tester for object-oriented programs.

– A software developed by this group– It can generate random test cases (more details

later)– Example:

Page 7: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

Methodology

Page 8: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Method Sequence

– a method sequence, or simple sequence, is a sequence of method calls

– Each call named S.i which means the value returned by the ith previous method call in sequence S

Page 9: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Extending Sequence– extension operation: takes zero or more

sequences and produces a new sequence.– operator extend(m, seqs, vals)• m: is a method with formal parameters of type T1; : : : ;

Tk.• seqs: is a list of sequences.• vals: is a primitive values v1 : T1; : : : ; vk : Tk, or it is the

return value s:i of the i-th method call for a sequence s appearing in seqs.

Page 10: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Example:

Page 11: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Feedback-directed Generation– build sequences incrementally– as soon as a sequence is built, execute to ensure

non-redundant and legal objects (filters & contracts)

– GenerateSequences(classes, contracts, filters, timeLimit)• classes: a list of classes for which to create sequences• contracts: a list of contracts• filters: a list of filters• timeLimit: a time limit to stop generation process

Page 12: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo
Page 13: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Generate Sequence

– Step1 Create new Sequence– Step2 Discard duplication– Step3 Execute new sequence– Step4 Check contracts– Step 5 added in test sequence set.

Page 14: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Boolean vector– a boolean flag s:i.extensible. (whither it can be

used as input in new method call)– Be used in filters (explain later)

• m(T1 ...Tk) at line 5

– Use reflection to load dll (being tested), store all method infos and classes infos into collection. Select randomly.

– RandomMethodOrConstructorUniform(),return a reflecton.runtimemethodinfo

Page 15: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• randomSeqsAndVals(T1...Tk)– Types is from methodinfo– The length of sequence is decided by limited time – When a new method call created, put in plan,

when time out, write in cs file.• Parameters– Primitive type, select a primitive value form fixed

pool of values– Reference type • Use one already exist in sequence (in plan).• New one• Null

Page 16: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Primitive Value Pool:

Page 17: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Extend Sequence• The method is explained in previous slide

• Discard duplicates– Check whither equivalent sequence was already

created in previous– Non error sequence set– Error sequence set

• Execute sequence– Execute calls in sequence one by one. And check

contracts after each all.– If conflict with contract, set violated be true

Page 18: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Default Contracts

Page 19: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Filtering– setExtensibleFlags (newSeq; flters; ~o) line19

• Function: determine which values of a sequence are extensible and should be used as inputs to new method calls

– Equality.• uses the equals() method to determine if the resulting

object has been created before.

– Null.• set newSeq:i.extensible to false iff the corresponding

object is null. Such as void method

Page 20: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

– Exceptions.• If exception occurs, even it does not conflict with

contract, still set extendable false

Page 21: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

Evaluation

Page 22: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

JFP RP JPFU RPU0

0.2

0.4

0.6

0.8

1

1.2

BinTreeBHeapFibHeapTreeMap

Block Coverage

Page 23: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

Block Coverage Running Time

JFP RP JFPu Rpu0

5

10

15

20

25

BinTreeBheapFibHeapTreeMap

Page 24: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Test common libs – REDUCE similar with Junit and Nunit– Used feedback-RANDOOP

Page 25: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Open Source:• For Java:– http://code.google.com/p/randoop/

• For .Net:– http://randoop.codeplex.com/

Page 26: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• RUNDOOP2 for C# published 09/08/2010

• Main structure:

Page 27: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Randoop– Load target dll by reflection, analysis and generate

config file (xml)• RandoopBare– According to config file, generate test cases. – Staticmanager calculates figures.– Generate log

Page 28: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Example 1– Test target .Net System.Data.dll– Right now just can test dlls in C:\WINDOWS\

Microsoft.NET\Framework\v2.0.50727– Randoop needs use csc.exe to compile test cases

Page 29: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Test Case:

Page 30: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• My test cases:• Lib- RandoopTestLib– Addition– Subtract– Arithmetic

Page 31: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Subtract

Page 32: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo
Page 33: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• Put dll into C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

• For Int: -10 -3 -2 -1 0 1 2 3 10

• For Long: -10 -3 -2 -1 0 1 2 3 10

• For String and Object

I can not find it.

Page 34: Feedback-Directed Random Test Generation Automatic Testing & Validation CSI5118 By Wan Bo

• The test case