Knowledge-base
Search…
Home
Samman Technical Coaching
Software craftsmanship
Practices
The Software Craftsman
Technical debt workshop
Functional Programming made easy in C# with Language-ext
F# for OO programmers
Domain Modeling Made Functional
Testing
Katas
TDD
Improve your software quality with Property-Based Testing
A journey to Property-Based Testing
Clean Code
Clean Architecture
Write S.O.L.I.D code
Mocking
Gilded Rose (Approval Testing)
Mikado method
Pure functions
Theatrical players refactoring Kata
Functional Programming made easy in Java & C#
Refactoring journey
Software Design X-Rays
The Programmer's Brain
Software Architecture
Agile coaching
Leadership
Serious games
Xtrem Reading
My Activity
Powered By
GitBook
A journey to Property-Based Testing
The purpose of this workshop is to understand by the practice an approach to testing that allows us to identify and check our business invariants. We will discover :
How it differs from traditional sampling approach (example-based testing)
Its advantages and limits
Source code
Source code is available
here
in :
Scala : Scalatest / Scalacheck
C# 10 : XUnit / FsCheck / Language-Ext / FluentAssertions
Connection - Calculator
Connect participants to the topic by making them write Unit Tests on the Calculator class :
Debriefing :
Concepts - PBT
Go through slides 4 to 15 to explain the different concepts :
Example-Based Testing vs PBT
What is PBT ?
Addition properties example
PBT by hands
Scalacheck / FsCheck / QuickCheck
Associated concepts
Demonstrate how to write properties on the Calculator, you can use the
step-by-step guide
to prepare yourself
Concrete Practice
Postal Parcel
Open `PostalParcel` :
Identify properties – 5’
What are the invariants ?
Write them in `PostalParcelPropertiesFlatSpec` with ScalaCheck / FsCheck - 15’
Collective debriefing – 5’
Scala
C#
Bank withdrawal
Open `AccountService` :•Identify properties – 5’
What should we do to check those properties ?
Demonstrate how you could write properties on those knowing that Command and Account are tightly coupled as inputs :
Using properties + input filtering (when)
Using properties and Builder
How we would write tests on Bank withdrawal in real life (with Parameterized tests
Rental Calculator - PBT as a refactoring tool
Open `RentalCalculator`
Imagine this code is running in production and business is happy with it
Imagine you need to adapt it, but you need to be sure that you don’t introduce any regression
How PBT can help us ?
Let them code - 15'
Collective debriefing - 5'
Scala
C#
Conclusion
When to apply PBT in real life
Associated anti-patterns
Reflect : Think about your last development, how this approach could have helped you ?
Resources
ScalaCheck documentation
Scala exercises on PBT :
https://www.scala-exercises.org/scalacheck/generators
"Functions for nothing, and your tests for free" Property-based testing and F# - George Pollard
Property based testing - step by step :
https://www.leadingagile.com/2018/04/step-by-step-toward-property-based-testing/
Slide deck to support workshop
Previous
Improve your software quality with Property-Based Testing
Next
Clean Code
Last modified
5mo ago
Copy link
Contents
Source code
Connection - Calculator
Concepts - PBT
Concrete Practice
Conclusion
Resources