Luis Presa Collada Pablo Caal Surez Sofa Garca Barbs Daniel Finca - - PowerPoint PPT Presentation

luis presa collada
SMART_READER_LITE
LIVE PREVIEW

Luis Presa Collada Pablo Caal Surez Sofa Garca Barbs Daniel Finca - - PowerPoint PPT Presentation

Luis Presa Collada Pablo Caal Surez Sofa Garca Barbs Daniel Finca Martnez Introduction Some definitions Property testing Property, Law or Invariant Test generation Non-deterministic test execution Property testing /


slide-1
SLIDE 1

Luis Presa Collada Pablo Cañal Suárez Sofía García Barbés Daniel Finca Martínez

slide-2
SLIDE 2

Introduction

slide-3
SLIDE 3

Some definitions

▪ Property testing ▪ Property, Law or Invariant ▪ Test generation ▪ Non-deterministic test execution

slide-4
SLIDE 4

Property testing / Generative testing

▪ Writing code: Solving a problem. ▪ Writing tests: Checking whether or not our solution is valid ▪ Integer array sorting function

slide-5
SLIDE 5

Property / Law / Invariant

▪ Characteristic(s) that qualify the result of the execution of certain piece of code. ▪ Some are valid in many cases. Some are not. ▪ Previous integer array sorting function properties:

– Sorting an array would never modify its content (add, remove, change elements). – Sorting an already sorted array does nothing to it. – Sorting a sequence of numbers results in an ordered list (Quite obvious BTW).

slide-6
SLIDE 6

Test generation => Ad-hoc generators

▪ Well, I have the properties. What do I do now?

– Good question by the way! ( :

slide-7
SLIDE 7

NDE => Non-deterministic execution

▪ Randomness is a pain in the… Yeah. ▪ Sometimes test pass. Some others… well you just simply don’t have a clue about what happened.

slide-8
SLIDE 8

Why is it awesome?

slide-9
SLIDE 9

Three main features...

▪ Coverage ▪ Reproducible ▪ Shrink

slide-10
SLIDE 10

Traditional testing...? Sure?

▪ Coverage function serialize<T>(instance: T, params: Parameters): string { /* code */ }

slide-11
SLIDE 11

Discover uncovered code paths!

▪ Coverage test( ‘Should be able to read itself’ , () => { fc.assert( fc.property( fc. jsonObject(), (instance, params) => { expect(deserialize( serialize(instance, params))).toEqual( instance); }) ) });

slide-12
SLIDE 12

Replay the same test!

▪ Reproducible Error: Property failed after 1 tests ( seed: 1527423434693, path: "0:0:0“ ): ["","",""] Shrunk 2 time(s) Got error: Property failed by returning false

slide-13
SLIDE 13

Replay the same test!

▪ Reproducible test('the failing test', () => fc.assert ( fc.property ( // check method ), { seed: 1527423434693, // seed and path taken from the previous slide path: "0:0:0" } ));

slide-14
SLIDE 14

Understand your errors...

▪ Shrink test('the failing test', () => fc.assert ( fc.property ( // check method ), { verbose: true } ));

slide-15
SLIDE 15

Understand your errors...

▪ Shrink Error: Property failed after 1 tests ( seed: 1527423434693, path: "0:0:0“ ): ["","",""] Shrunk 2 time(s) Got error: Property failed by returning false Encountered failures were:

  • ["", "JeXPqIQ6”, ">q"]
  • ["", "", ">q"]
  • ["", "", ""]
slide-16
SLIDE 16

Who could be interested?

slide-17
SLIDE 17

Stakeholders

Nicolas Dubien The GitHub team

slide-18
SLIDE 18

Stakeholders You as a developer!

slide-19
SLIDE 19

Packages using Fast-check!

slide-20
SLIDE 20

How to Fast-Check

slide-21
SLIDE 21

Hang on! Configure jest script

"scripts": { "test": "jest" }, "jest": { "moduleFileExtensions": ["ts", "tsx", "js"], "globals": {"ts-jest": {"tsConfig": "tsconfig.json"}}, "transform": {"^.+\\.(ts|tsx)$": "ts-jest"}, "testMatch": ["**/specs/*.+(ts|tsx|js)"] },

slide-22
SLIDE 22

And finally… npm install --save-dev fast-check

slide-23
SLIDE 23
slide-24
SLIDE 24

Let’s go slow, for now

Method to test Test Method

slide-25
SLIDE 25

Boring stuff, right? Fast! Check this!

▪ Numbers: (and you can bound them!)

– Natural – Negative – Floating point

▪ Random strings:

– Ascii, Unicode. – Length bounded – Char bit size

slide-26
SLIDE 26

Not convinced yet? More random Strings!!

▪ Json structure

  • >

.json(maxLength) ▪ Ipv4, Ipv6

  • >

.ipv4() .ipv6() ▪ URLs

  • >

.webUrl() ▪ Email addresses

  • >

.emailAddress() ▪ UUID

  • >

.uuid() .uuidV(version)

slide-27
SLIDE 27

More “normal” things

▪ Fixed contant

  • >

.constant(value) ▪ Picked constant

  • >

.oneOf(array[value]) ▪ Array: of anArbitrary. ▪ Subarray: picks elements from an array. You may shuffle. ▪ Set: Unique values of Arbitrary.

slide-28
SLIDE 28

anything(settings:ObjectConstraints.Settings)

  • You need an input
  • You configure it
  • You use the function
  • You have your test :D
slide-29
SLIDE 29

RECUR_RECUR__RECURSION__SION_SION

slide-30
SLIDE 30

Crazy, random, and recursive.

slide-31
SLIDE 31

Don’t understimate its power

▪ Transform and derive Arbitraries:

– Map – Filter

▪ Commands (PreCondition -> Execution -> PostCondition) ▪ Support for asynchronous :

– Command – Arbitraries – Handle Race Conditions

▪ Shedulers ▪ Wrap calls.

slide-32
SLIDE 32

Someone said API?

slide-33
SLIDE 33
slide-34
SLIDE 34

{api}

▪ Arbitraty

export declare abstract class Arbitrary<T>

▪ Shrinkable

export declare class Shrinkable<T, TShrink extends T = T>

▪ anything(settings?) ▪ asciiString(minLength?, maxLength?) ▪ double() ▪ float() ▪ …

slide-35
SLIDE 35

Quality Attributes

slide-36
SLIDE 36

Why use it?

▪ Offers plenty of types ▪ Extendable ▪ Filtering options ▪ Adds debugging advantages ▪ Race conditions detection

slide-37
SLIDE 37

Fast (and active) Check

slide-38
SLIDE 38

Fast (and active) Check

slide-39
SLIDE 39

Fast Releases

1.23.0

slide-40
SLIDE 40

Thanks for fast- checking with us!!