Skip to content

Commit 40e856b

Browse files
committed
parameterized tests added
1 parent 0320b28 commit 40e856b

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

presentation/slides.md

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -834,40 +834,39 @@ expect(emailService.send).toHaveBeenCalledWith(order.customerEmail)
834834

835835
---
836836
layout: code
837-
code-size: 0.95em
837+
code-size: 1.07em
838838
h1:
839839
type: brackets
840840
color: muted
841-
position: 2
841+
position: all
842842
---
843843

844844
# Parameterized Tests
845845

846-
```ts {1-6|8-14|all}
847-
// ✅ Use parameterized: same logic, different inputs
848-
test.each([
849-
{ input: -1, expected: false },
850-
{ input: 0, expected: false },
851-
{ input: 2, expected: true },
852-
{ input: 97, expected: true },
853-
])("isPrime($input) returns $expected", ({ input, expected }) => {
854-
expect(isPrime(input)).toBe(expected)
855-
})
846+
```python {1-3|5-7|9-11|all}
847+
@pytest.mark.parametrize("val", [0, 50, 100])
848+
def test_accepts_valid_range(val):
849+
assert is_valid_percentage(val)
850+
851+
@pytest.mark.parametrize("val", [-1, -20, 101, 200])
852+
def test_rejects_out_of_range(val):
853+
assert not is_valid_percentage(val)
856854

857-
// ❌ Don't parameterize: different scenarios, different intent
858-
// "user with expired token" vs "user with no token"
859-
// → separate tests with descriptive names
855+
@pytest.mark.parametrize("val", [None, float('nan')])
856+
def test_rejects_edge_cases(val):
857+
assert not is_valid_percentage(val)
860858
```
861859

862-
<div class="mt-4 text-center text-2xl grid">
863-
<div v-click.hide="1" class="text-emerald-400 col-start-1 row-start-1">Boundaries &amp; equivalence classes → <strong>parameterize</strong></div>
864-
<div v-click="[1,2]" class="text-orange-400 col-start-1 row-start-1">Different scenarios or business rules → <strong>separate tests</strong></div>
860+
<div class="mt-2 text-center text-2xl grid">
861+
<div v-click.hide="1" class="text-emerald-400 col-start-1 row-start-1"><strong>Valid values</strong> — boundaries + middle of the valid range</div>
862+
<div v-click="[1,2]" class="text-cyan-400 col-start-1 row-start-1"><strong>Out of range</strong> — boundaries + equivalence partitions</div>
863+
<div v-click="[2,3]" class="text-pink-400 col-start-1 row-start-1"><strong>Edge cases</strong> — null, NaN, Infinity</div>
865864
</div>
866865

867866
<!--
868-
Parameterized tests shine for boundary value analysis and equivalence partitioning — exactly the cases we discussed earlier.
869-
But they obscure intent when scenarios are conceptually different. When a parameterized test fails, the failure message is often just "row 3 failed" — you lose the descriptive test name that tells you WHAT broke.
870-
Rule of thumb: if you can describe all cases with "same function, different numbers" → parameterize. If each case has a different story → separate tests.
867+
Parameterized tests shine for boundary value analysis and equivalence partitioning — exactly the cases from the earlier Boundaries slide.
868+
Same function, different inputs → parameterize. Different scenarios with different intent → write separate tests with descriptive names.
869+
When a parameterized test fails, the framework shows which input failed. JUnit 5 @ParameterizedTest, NUnit [TestCase], xUnit [Theory].
871870
-->
872871

873872
---

0 commit comments

Comments
 (0)