Skip to content

Commit

Permalink
slides: add mocking frameworks
Browse files Browse the repository at this point in the history
- tdd schools
- tdd image
  • Loading branch information
draptik committed Dec 13, 2019
1 parent 7d33d24 commit b2b399b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 22 deletions.
60 changes: 42 additions & 18 deletions presentation/slides/03-integration-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,18 @@

---

```csharp
// Arrange
var mailer = Substitute.For<IMailer>();

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

---

Expand All @@ -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<IMailer>(); // <--
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
14 changes: 10 additions & 4 deletions presentation/slides/04-tdd.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/)
Binary file added presentation/slides/images/TDD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b2b399b

Please sign in to comment.