SLIDE 1 Enrico Campidoglio
Testing the Essential
with AutoFixture
@ecampidoglio
SLIDE 2
Small Expressive
+ − −
Premise:
SLIDE 3
Essential
SLIDE 4
AutoFixture 3 unit testing
patterns
SLIDE 5
Context
System
under test System
under test 123 Set()
SLIDE 6 Set()
123
System
under test
Fixture
true
‘Bar’ 982 null
SLIDE 7
3 parts
SLIDE 8
Act Assert Arrange
SLIDE 9
Act Assert Arrange
SLIDE 10 System
under test Set()
Fixture
true
982 null ‘Bar’ 123
SLIDE 11
System
under test
Fixture
Set()
SLIDE 12
Easier
to change Fewer
explicit calls
SLIDE 13
Scenario
Fixture
SLIDE 14
Scenario
Fixture
SLIDE 15
3 unit testing
patterns
SLIDE 16
Anonymous Data
1
SLIDE 17
Any input value that exercises the code path under test
SLIDE 18 public bool IsPositive(int value) {
return value > 0;
}
Anonymous
SLIDE 19
Equivalence Classes
2
SLIDE 20
The group of input values that exercise the same path through the code
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
Test Data Builder
3
SLIDE 23
A factory that creates values used to test specific code paths
SLIDE 24 Default 80 %
Customize 20 %
SLIDE 25 public void Fork(int value) {
if (value > 9) { // Do this } else { // Do that } }
Asmallpositivenumber isgoodenough Tocovermostpossible
codepaths
SLIDE 26
An implementation of Conway’s Game of Life
written in C#
SLIDE 27
3 takeaways
SLIDE 28 Easier maintenance
Less coupling
SLIDE 29 github.com/autofixture
- stackoverflow.com/tags/autofixture
SLIDE 30
Thank you.
@ecampidoglio