You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-3/1-implement-and-rewrite-tests/testing-guide.md
+11-14Lines changed: 11 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,11 +7,10 @@ Input ──▶ Function ──▶ Output
7
7
```
8
8
9
9
A function
10
-
11
10
- Takes **input** (via **arguments**)
12
11
- Does some work
13
12
- Produces **one output** (via a **return value**)
14
-
13
+
15
14
Example:
16
15
17
16
```
@@ -20,18 +19,17 @@ sum(2, 3) → 5
20
19
21
20
Important idea: the same input should produce the same output.
22
21
23
-
## 2. Testing Means Predicting
24
22
25
-
Testing means:
23
+
## 2. Testing Means Predicting
26
24
25
+
Testing means:
27
26
> If I give this input, what output should I get?
28
27
28
+
29
29
## 3. Choosing Good Test Values
30
30
31
31
### Step 1: Determining the space of possible inputs
32
-
33
32
Ask:
34
-
35
33
- What type of value is expected?
36
34
- What values make sense?
37
35
- If they are numbers:
@@ -41,7 +39,7 @@ Ask:
41
39
- What are their length and patterns?
42
40
- What values would not make sense?
43
41
44
-
### Step 2: Choosing Good Test Values
42
+
### Step 2: Choosing Good Test Values
45
43
46
44
#### Normal Cases
47
45
@@ -50,9 +48,10 @@ These confirm that the function works in normal use.
50
48
- What does a typical, ordinary input look like?
51
49
- Are there multiple ordinary groups of inputs? e.g. for an age checking function, maybe there are "adults" and "children" as expected ordinary groups of inputs.
52
50
51
+
53
52
#### Boundary Cases
54
53
55
-
Test values exactly at, just inside, and just outside defined ranges.
54
+
Test values exactly at, just inside, and just outside defined ranges.
56
55
These values are where logic breaks most often.
57
56
58
57
#### Consider All Outcomes
@@ -65,7 +64,6 @@ Every outcome must be reached by at least one test.
65
64
#### Crossing the Edges and Invalid Values
66
65
67
66
This tests how the function behaves when assumptions are violated.
68
-
69
67
- What happens when input is outside of the expected range?
70
68
- What happens when input is not of the expected type?
71
69
- What happens when input is not in the expected format?
@@ -75,19 +73,18 @@ This tests how the function behaves when assumptions are violated.
75
73
### 1. Using `console.assert()`
76
74
77
75
```javascript
78
-
// Report a failure only when the first argument is false
79
-
console.assert(sum(4, 6) ===10, "Expected 4 + 6 to equal 10");
76
+
// Report a failure only when the first argument is false
77
+
console.assert(sum(4, 6) ===10, "Expected 4 + 6 to equal 10");
80
78
```
81
79
82
80
It is simpler than using `if-else` and requires no setup.
83
-
81
+
84
82
### 2. Jest Testing Framework
85
83
86
84
```javascript
87
-
describe("Description for this case used for grouping")
88
85
test("Should correctly return the sum of two positive numbers", () => {
0 commit comments