Skip to content

Commit 0320b28

Browse files
committed
more code examples
1 parent 912e7b5 commit 0320b28

1 file changed

Lines changed: 78 additions & 1 deletion

File tree

presentation/slides.md

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,48 @@ Boundary Value Analysis: Instead of using semi-random values, we use values at t
358358
Edge Case Testing: Add tests for NULL, PositiveInfinity, NaN, ...
359359
-->
360360

361+
---
362+
layout: code-comparison
363+
before-label: Equivalence Partitioning
364+
after-label: Edge Cases
365+
code-size: 0.85em
366+
---
367+
368+
# Boundaries
369+
370+
## isValidPercentage(n)
371+
372+
::before::
373+
374+
```ts {1-2|4-6|0}
375+
// All negative values belong to the same partition
376+
test("rejects negative", () => expect(valid(-20)).toBe(false))
377+
378+
// The percentage validation function has 2 more partitions
379+
test("accepts valid", () => expect(valid(20)).toBe(true))
380+
test("rejects over 100", () => expect(valid(200)).toBe(false))
381+
```
382+
383+
384+
### Boundary Value Analysis
385+
386+
387+
```ts {0|1-2|3-4|0}
388+
test("low boundary", () => expect(valid(-1)).toBe(false))
389+
test("low boundary", () => expect(valid(0)).toBe(true))
390+
test("high boundary", () => expect(valid(100)).toBe(true))
391+
test("high boundary", () => expect(valid(101)).toBe(false))
392+
```
393+
394+
::after::
395+
396+
```ts {0|all}
397+
test("null", () => expect(valid(null)).toBe(false))
398+
test("NaN", () => expect(valid(NaN)).toBe(false))
399+
test("Infinity", () => expect(valid(Infinity)).toBe(false))
400+
test("string", () => expect(valid("50")).toBe(false))
401+
```
402+
361403
---
362404
layout: section
363405
---
@@ -603,11 +645,12 @@ h1:
603645

604646
# State vs Behavior
605647

606-
<v-clicks>
648+
<v-clicks depth="2">
607649

608650
- **State Testing**
609651
- Assertion Territory
610652
- Validate that a property has a certain value
653+
- ✅ Most tests should do state testing
611654
- **Behavior Testing**
612655
- Mocking Territory
613656
- Validate that a method was (not) called
@@ -623,7 +666,41 @@ State: When updating an entity, the audit fields LastModifiedBy and LastModified
623666
Behavior: Verify that a method was (not) called, or called with specific arguments. Example: verify that an email is (not) sent, or that Repository.Save() is called.
624667
-->
625668

669+
---
670+
layout: code-comparison
671+
before-label: State Testing
672+
after-label: Behavior Testing
673+
code-size: 0.93em
674+
---
675+
676+
# State vs Behavior
677+
678+
::before::
679+
680+
```ts {2-5|7|all}
681+
test("setsStatusToCompleted", () => {
682+
const emailService = mock<EmailService>()
683+
const order = new Order(emailService)
626684

685+
order.place()
686+
687+
expect(order.status).toBe("completed")
688+
})
689+
```
690+
691+
::after::
692+
693+
```ts {0|7-8|all}
694+
test("sendsConfirmationEmail", () => {
695+
const emailService = mock<EmailService>()
696+
const order = new Order(emailService)
697+
698+
order.place()
699+
700+
expect(emailService.send)
701+
.toHaveBeenCalledWith(order.email)
702+
})
703+
```
627704

628705
---
629706
layout: section

0 commit comments

Comments
 (0)