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: README.md
+34-31Lines changed: 34 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,17 +28,17 @@ in all changes and derivate works.
28
28
29
29
30
30
# ET on Embedded Targets
31
-
On *embedded targets*, ET requires a serial port to output test results to the host. (The host computer must be running a serial utility to visualize the output from the embedded target.) ET provides a simple adaptation layer for any UART/USART in polling mode without interrupts. Please also see [Running on Embedded Board](#running-on-embedded-board).
31
+
On *embedded targets*, ET requires a serial port to output test results to the host. (The host computer must be running a serial utility to visualize the output from the embedded target.) ET provides a simple adaptation layer for any UART/USART in polling mode without interrupts. Please also see [Running ET on Host Computers](#et-on-host-computers).
32
32
33
33
<palign="center"><imgsrc="img/ET-emb.png"/></p>
34
34
35
35
# ET on Host Computers
36
-
ET can also run on *host computers* (Windws, Lunux, macOS) in console mode (in that case, ET takes advantage of `<stdio.h>`).
36
+
ET can also run on *host computers* (Windows, Linux, macOS) in console mode (in that case, ET takes advantage of `<stdio.h>`).
37
37
38
38
<palign="center"><imgsrc="img/ET-host.png"/></p>
39
39
40
40
# ET Code Organization
41
-
ET consists of one small header file ([<b>et.h</b>](et.h)) and one small source file ([<b>et.c</b>](et.c)), which are both located in the root directory of the ET distribution. Additionally, the ET ditro contains [examples](examples) and embedded code for the [STM32 NUCLEO-C031C6 board](#running-on-embedded-board) (other boards can be added following that simple example).
41
+
ET consists of one small header file ([<b>et.h</b>](et/et.h)) and one small source file ([<b>et.c</b>](et/et.c)), which are both located in the root directory of the ET distribution. Additionally, the ET distro contains [examples](examples) and embedded code for the [STM32 NUCLEO-C031C6 board](#et-on-embedded-targets) (other boards can be added following that simple example).
42
42
43
43
```
44
44
Embedded-Test/ - root of the Embedded Test distribution
@@ -73,20 +73,24 @@ Embedded-Test/ - root of the Embedded Test distribution
73
73
74
74
```
75
75
> **NOTE**<br>
76
-
The example code is organized in the standard way for unit testing, into the `src` directory with the CUT and `test` directory with test-fixture and makefiles to build and run the tests.
76
+
The example code is organized in the standard way for unit testing, into the `src` directory with the CUT and `test` directory with test-fixture and Makefiles to build and run the tests.
77
77
78
78
79
79
# Basic ET Example in C
80
80
Here is the basic test fixture (see [examples/basic/test/test.c](examples/basic/test/test.c)), which tests a simple `sum(x,y)` function that returns `x+y`. The explanation section following the listing highlights the main points:
81
81
82
82
```c
83
-
[1] #include "sum.h"/* Code Under Test (CUT)*/
84
-
[2] #include "et.h"/* ET: Embedded Test*/
83
+
[1] #include "sum.h"// Code Under Test (CUT)
84
+
[2] #include "et.h"// ET: Embedded Test
85
85
86
-
[3] voidsetup(void) { ... }
87
-
[4] void teardown(void) { ... }
86
+
[3] voidsetup(void) {
87
+
// executed before *every* non-skipped test
88
+
}
89
+
[4] void teardown(void) {
90
+
// executed after *every* non-skipped and non-failing test
91
+
}
88
92
89
-
/* test group -------------------------------------------------*/
93
+
// test group ---------------------------------------------------
90
94
[5] TEST_GROUP("Basic") {
91
95
92
96
[6] TEST("CUT test (passing)") {
@@ -95,21 +99,21 @@ Here is the basic test fixture (see [examples/basic/test/test.c](examples/basic/
95
99
}
96
100
97
101
[9] SKIP_TEST("test (skipped)") {
98
-
[10] VERIFY(3 == 2*2); /* this would fail, but it's not checked*/
102
+
[10] VERIFY(3 == 2*2); // this would FAIL, but it's not checked
99
103
}
100
104
101
105
[11] TEST("CUT test (failing)") {
102
106
VERIFY(5 == sum(2, 3));
103
-
[12] VERIFY(4 == sum(3, 2)); /* <--- fails */
107
+
[12] VERIFY(4 == sum(3, 2)); // <--- FAILS
104
108
}
105
109
106
110
[13] TEST("simple test (passing)") {
107
111
VERIFY(4 == 2*2);
108
112
}
109
113
110
-
[14] } /* TEST_GROUP()*/
114
+
[14] } // TEST_GROUP()
111
115
112
-
/* dependencies for the CUT -----------------------------------*/
116
+
// dependencies for the CUT -------------------------------------
113
117
[15] . . .
114
118
```
115
119
@@ -127,7 +131,7 @@ Here is the basic test fixture (see [examples/basic/test/test.c](examples/basic/
127
131
The "test group" in ET is the "test runner" function (`ET_run()`), which executes tests specified as the body of this function.
128
132
129
133
130
-
`[6]` The ET macro `TEST()` defines a single test. The macro takes the test name, which is arbitary string to be output to identify the test.
134
+
`[6]` The ET macro `TEST()` defines a single test. The macro takes the test name, which is arbitrary string to be output to identify the test.
131
135
132
136
`[7]` The ET macro `VERIFY()` verifies the "test assertion". The macro takes a Boolean expression, which must evaluate to 'true'. If the expression evaluates to 'false' the test fails and ET will print the group-name and line number of the failing `VERIFY()`.
133
137
@@ -138,22 +142,21 @@ The "test group" in ET is the "test runner" function (`ET_run()`), which execute
138
142
`[10]` The body of a "skipped" test is not executed. Neither are the `setup()` and `teardown()` callbacks for that test. This means that the `VERIFY()` "test assertion" is not evaluated, so it does not matter whether it evaluates to 'true' or 'false'.
139
143
140
144
### Failing Test in ET
141
-
142
145
`[11]` This is an example of a *failing* "test.
143
146
144
147
`[12]` Typically a test fails because one of the `VERIFY()` macros evaluates to 'false', which causes the **whole test to fail**. (A test can be also forced to fail by calling the `FAIL()` macro, which provides opportunity to output a "note" as to why a test was forced to fail.)
145
148
146
149
> **NOTE**<br>
147
-
In ET, a failing test **stopps** the whole run and causes an "exit" from the test-fixture (please see [Running on Embedded Board](#running-on-embedded-board) for discussion of what "exit" means on embedded targets). The rationale is that a failing test means that the following code is not to be trusted, so continuaiton makes no sense. This aligns with the TDD workflow, which requires *fixing* any failing test before continuing with other tests.
150
+
In ET, a failing test **stops** the whole run and causes an "exit" from the test-fixture (please see [Running on Embedded Board](#running-on-embedded-board) for discussion of what "exit" means on embedded targets). The rationale is that a failing test means that the code downstream the failure is not to be trusted (the software is in an unpredictable state), so continuation makes no sense. This aligns with the TDD workflow, which requires *fixing* any failing test before continuing with other tests.
148
151
149
-
`[13]` Any `TEST()` following a failing test is *not* executed.
152
+
`[13]` Any `TEST()` downstream a failing test is *not* executed.
150
153
151
154
`[14]` The test group (see [5]) needs to be closed by a closing-brace `}`.
152
155
153
-
`[15]` The test group can be foolowed by any additional code, typically implementing some dependencies of the CUT.
156
+
`[15]` The test group can be followed by any additional code, typically implementing some dependencies of the CUT.
154
157
155
158
## Running ET on the Host
156
-
The ET [examples](examples/basic/test) provide a simple [Makefile]([examples](examples/basic/test/Makefile) to build the tests and run them on a host (Windows, Linux, or macOS). Here is an example of running the basic test on the host (Windows command prompt in this case.)
159
+
The ET [examples](examples/basic/test) provide a simple [Makefile]([examples](examples/basic/test/Makefile) to build the tests and run them on a host (Windows, Linux, or macOS). Here is an example of running the basic test on the host (Windows command prompt in this case.) This test intentionally fails (which is more interesting than a successful test.)
@@ -211,14 +214,14 @@ This adaptation uses `<stdio.h>` for output to the console and `<stdlib.h>` for
211
214
212
215
213
216
## Running ET on Embedded Board
214
-
The ET [examples](examples/basic/test) provide a simple makefile (see [nucleo-c031c6.mak](examples/basic/test/nucleo-c031c6.mak)) to build the tests for the STM32 NUCLEO-C031C6 shown below.
217
+
The ET [examples](examples/basic/test) provide a simple Makefile (see [nucleo-c031c6.mak](examples/basic/test/nucleo-c031c6.mak)) to build the tests for the STM32 NUCLEO-C031C6 shown below.
The STM32 NUCLEO board has been selected because it can to be programmed by simply copying the binary image to the board enumerated as a USB drive.
220
223
221
-
The ET distribution contains all files requried to build the binary image for the NUCLEO-C031C6 board. However, you still need to provide the GCC-ARM compiler and the serial terminal utility to receive the output produced by the board. To run the test on the STM32 NUCLEO-C031C6, you open a terminal window and type:
224
+
The ET distribution contains all files required to build the binary image for the NUCLEO-C031C6 board. However, you still need to provide the GCC-ARM compiler and the serial terminal utility to receive the output produced by the board. To run the test on the STM32 NUCLEO-C031C6, you open a terminal window and type:
222
225
223
226
> **NOTE**<br>
224
227
The GCC-ARM cross-compiler for Windows as well as the `make` utility are available in the [QTools collection](https://github.com/QuantumLeaps/qtools) for Windows.
@@ -229,7 +232,7 @@ cd ET\examples\basic\test
229
232
make -f make_nucleo-c031c6 USB=g:
230
233
```
231
234
232
-
The follwing screen shot shows the build process, programming the board (by copying the binary image) and the test output on the [Termite serial terminal](https://www.compuphase.com/software_termite.htm).
235
+
The following screen shot shows the build process, programming the board (by copying the binary image) and the test output on the [Termite serial terminal](https://www.compuphase.com/software_termite.htm).
0 commit comments