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: 1-what-is-a-unit-tests.md
+8-10Lines changed: 8 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: "Introduction to Unit Testing"
2
+
title: "What is a Unit Test"
3
3
teaching:
4
4
exercises:
5
5
---
@@ -8,20 +8,18 @@ exercises:
8
8
9
9
- What is unit testing?
10
10
- Why do we need unit tests?
11
-
- What makes src code difficult to unit test?
12
11
13
12
::::::::::::::::::::::::::::::::::::::::::::::::
14
13
15
14
::::::::::::::::::::::::::::::::::::: objectives
16
15
17
16
- Define the key aspects of a good unit test (isolated, testing minimal functionality, fast, etc).
18
17
- Understand the key anatomy of a unit test in any language.
19
-
- Explain the benefit of unit tests on top of integration/e2e tests.
18
+
- Explain the benefit of unit tests on top of other types of tests.
20
19
- Understand when to run unit tests.
21
20
22
21
::::::::::::::::::::::::::::::::::::::::::::::::
23
22
24
-
## What is unit testing?
25
23
26
24
Unit testing is a way of verifying the validity of a code base by testing its smallest individual components, or **units**.
27
25
@@ -36,14 +34,14 @@ Several key aspects define a unit test. They should be...
36
34
37
35
::::::::::::::::::::::::::::::::::::: callout
38
36
39
-
####Other forms of testing
37
+
### Other forms of testing
40
38
41
39
There are other forms of testing, such as integration testing in which two or more units of a code base are tested to verify that they work together, or that they are correctly **integrated**.
42
40
However, today we are focusing on unit tests as it is often the case that many of these larger tests are written using the same test tools and frameworks, hence we will make progress with both by starting with unit testing.
43
41
44
42
::::::::::::::::::::::::::::::::::::::::::::::::
45
43
46
-
###What does a unit test look like?
44
+
## What does a unit test look like?
47
45
48
46
All unit tests tend to follow the same pattern of Given-When-Then.
49
47
@@ -59,7 +57,7 @@ All unit tests tend to follow the same pattern of Given-When-Then.
59
57
60
58
::::::::::::::::::::::::::::::::::::: challenge
61
59
62
-
####Challenge 1: Write a unit test in sudo code.
60
+
### Challenge 1: Write a unit test in sudo code.
63
61
64
62
Assuming you have a function `reverse_array` which reverses the order of an allocated array. Write a unit test in pseudo code for `reverse_array` using the pattern above.
65
63
@@ -83,7 +81,7 @@ for each element in `input_array`:
83
81
:::::::::::::::::::::::::::::::::
84
82
::::::::::::::::::::::::::::::::::::::::::
85
83
86
-
###When should unit tests be run?
84
+
## When should unit tests be run?
87
85
88
86
A major benefit of unit tests is the ability to identify bugs at the earliest possible stage. Therefore, unit tests should be run frequently throughout the development process. Passing unit tests give you and your collaborators confidence that changes to your code aren't modifying the previously expected behaviour, so run your unit tests...
89
87
@@ -96,7 +94,7 @@ A major benefit of unit tests is the ability to identify bugs at the earliest po
96
94
97
95
Basically, all the time.
98
96
99
-
###Do we really need unit tests?
97
+
## Do we really need unit tests?
100
98
101
99
Yes!
102
100
@@ -118,7 +116,7 @@ This is much clearer. We immediately have an idea of what could be going wrong a
118
116
119
117
::::::::::::::::::::::::::::::::::::: challenge
120
118
121
-
###Challenge 2: Unit test bad practices
119
+
## Challenge 2: Unit test bad practices
122
120
123
121
Take a look at [1-into-to-unit-tests/challenge](https://github.com/UCL-ARC/fortran-unit-testing-exercises/tree/main/episodes/1-into-to-unit-tests/challenge) in the exercises repository.
0 commit comments