diff --git a/presentation/slides/03-integration-testing.md b/presentation/slides/03-integration-testing.md index 200cfa4..5f51103 100644 --- a/presentation/slides/03-integration-testing.md +++ b/presentation/slides/03-integration-testing.md @@ -13,26 +13,18 @@ --- -```csharp -// Arrange -var mailer = Substitute.For(); - -var validCustomer = new ValidCustomer(); - -// We inject an interface to the system-under-test! -// Mocking frameworks can control the behaviour of the injected object! -var sut = new RegistrationService(mailer); - -// Act -sut.Register(validCustomer); +## Test matrix -// Assert -mailer.Received().Send(); -``` +![test-matrix](images/test-matrix.png) --- -## What should we test? +## Test matrix - Code smell + +- "overcomplicated code" quadrant + - wrong layer of abstraction + - missing encapsulation +- solution: move logic to domain object --- @@ -54,12 +46,44 @@ mailer.Received().Send(); - Stub (dummy, fake) - emulate **incoming** interactions +Many modern frameworks don't make this distinction. + --- ![test-double](images/test-double.png) --- -## Test matrix +## C# Mocking frameworks -![test-matrix](images/test-matrix.png) +- [Moq](https://github.com/moq/moq4) + - can also mock classes without interfaces +- [NSubstitute](https://nsubstitute.github.io/) + - nice API +- [FakeItEasy](https://fakeiteasy.github.io/) + - nice API + +--- + +### NSubstitute + +```csharp +// Arrange +var mailer = Substitute.For(); // <-- + +var validCustomer = new ValidCustomer(); + +// We inject an interface to the system-under-test! +// Mocking frameworks can control the behaviour of the injected object! +var sut = new RegistrationService(mailer); + +// Act +sut.Register(validCustomer); + +// Assert +mailer.Received().Send(); // <-- +``` + +--- + +examples in code diff --git a/presentation/slides/04-tdd.md b/presentation/slides/04-tdd.md index 3b49614..6da5d36 100644 --- a/presentation/slides/04-tdd.md +++ b/presentation/slides/04-tdd.md @@ -39,6 +39,10 @@ Let's use **testing** to **DRIVE** our **development**! --- +![tdd-cycle](images/TDD.png) + +--- + - no code without test - untested code should not go live - baby steps: only write code to make test pass @@ -71,8 +75,10 @@ Fizz-Buzz Kata ## Schools of TDD - **Classical** - - aka Detroit, Chicago, inside-out: Kent Beck + - aka Detroit, Chicago, "inside-out", "fake it til you make it" + - K. Beck: Test-Driven Development By Example - **London** - - aka moquist, outside-in: Freeman & Pryce -- Munich -- Hamburg + - aka moquist, "outside-in" + - Freeman & Pryce: Growing Object Oriented Software Guided by Tests +- Munich: [David Voelkl](https://www.youtube.com/watch?v=n62HN2DHDEU) +- Hamburg: [Ralph Westpfahl](https://ralfw.de/2019/07/hamburg-style-tdd/) diff --git a/presentation/slides/images/TDD.png b/presentation/slides/images/TDD.png new file mode 100644 index 0000000..3345adc Binary files /dev/null and b/presentation/slides/images/TDD.png differ