Testing the Essential with AutoFixture Enrico Campidoglio - - PowerPoint PPT Presentation

testing the essential
SMART_READER_LITE
LIVE PREVIEW

Testing the Essential with AutoFixture Enrico Campidoglio - - PowerPoint PPT Presentation

Testing the Essential with AutoFixture Enrico Campidoglio @ecampidoglio Premise: + Small Expressive Essential 3 unit testing AutoFixture patterns Context Set() 123 System System under test under test


slide-1
SLIDE 1

Enrico Campidoglio


Testing the Essential

with AutoFixture

@ecampidoglio


slide-2
SLIDE 2

Small Expressive

+ − −

Premise:

slide-3
SLIDE 3

Essential

slide-4
SLIDE 4

AutoFixture 3 unit testing
 patterns

slide-5
SLIDE 5

Context

System
 under test System
 under test 123 Set()

slide-6
SLIDE 6

Set()

123

System
 under test

Fixture

true

  • 1

‘Bar’ 982 null

slide-7
SLIDE 7

3 parts

slide-8
SLIDE 8

Act Assert Arrange

slide-9
SLIDE 9

Act Assert Arrange

slide-10
SLIDE 10

System
 under test Set()

Fixture

true

  • 1

982 null ‘Bar’ 123

slide-11
SLIDE 11

System
 under test

Fixture

Set()

slide-12
SLIDE 12

Easier
 to change Fewer
 explicit calls

slide-13
SLIDE 13

Scenario

Fixture

slide-14
SLIDE 14

Scenario

Fixture

slide-15
SLIDE 15

3 unit testing
 patterns

slide-16
SLIDE 16

Anonymous Data

1

slide-17
SLIDE 17

Any input value that exercises the code path under test

slide-18
SLIDE 18

public bool IsPositive(int value) {
 return value > 0;
 }

Anonymous

slide-19
SLIDE 19

Equivalence Classes

2

slide-20
SLIDE 20

The group of input values that exercise the same path through the code

slide-21
SLIDE 21

public void Fork(int value) {
 if (value > 3) { // Do this } else { // Do that } }

Fork(4); Fork(9); Fork(0); Fork(2);

Equivalenceclasses

slide-22
SLIDE 22

Test Data Builder

3

slide-23
SLIDE 23

A factory that creates values used to test specific code paths

slide-24
SLIDE 24

Default 80 %

Customize 20 %

slide-25
SLIDE 25

public void Fork(int value) {
 if (value > 9) { // Do this } else { // Do that } }

Asmallpositivenumber isgoodenough Tocovermostpossible
 codepaths

slide-26
SLIDE 26

An implementation of Conway’s Game of Life
 written in C#

slide-27
SLIDE 27

3 takeaways

slide-28
SLIDE 28

Easier maintenance

  • No magic values

Less coupling

slide-29
SLIDE 29

github.com/autofixture

  • stackoverflow.com/tags/autofixture
slide-30
SLIDE 30

Thank you.

@ecampidoglio