Skip to content

Commit e6c2a7b

Browse files
authored
Add some terminology
1 parent 857cb8c commit e6c2a7b

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

technical/automated_testing.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,36 @@ FreeCAD uses two different automated testing mechanisms, depending on the langua
88

99
## References
1010

11-
Some good references about automated testing:
11+
Some good references about automated testing...
12+
13+
Videos:
1214
* [Back to Basics: C++ Testing - Amir Kirsh - CppCon 2022 - YouTube.](https://www.youtube.com/watch?v=SAM4rWaIvUQ)
1315
* [Practical Advice for Maintaining and Migrating Working Code - Brian Ruth - CppCon 2021 - YouTube.](https://www.youtube.com/watch?v=CktRuMALe2A)
1416
* [The Science of Unit Tests - Dave Steffen - CppCon 2020 - YouTube.](https://www.youtube.com/watch?v=FjwayiHNI1w)
17+
18+
Books:
19+
* [Kent Beck. Test Driven Development by Example. ISBN 9780321146533](https://www.amazon.com/Test-Driven-Development-Kent-Beck/dp/0321146530)
1520
* [Michael Feathers. Working Effectively with Legacy Code. ISBN 0131177052.](https://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/0131177052)
1621
* [Jeff Langr. Modern C++ Programming with Test-Driven Development: Code Better, Sleep Better. ISBN 1937785483.](https://www.amazon.com/Modern-Programming-Test-Driven-Development-Better/dp/1937785483/)
1722

23+
## Terminology
24+
25+
Test writers have a few terms that are often used, but whose precise definitions aren't well-agreed-upon. The internet is full of arguments about what a "unit" is in
26+
"unit testing" for example. To Kent Beck, author of Test Driven Development (the seminal book on the subject), the "unit" is *the test itself*. In his concept, every test must be wholly isolated from
27+
every other test. They must be able to be run singly, or as part of an entire suite. While that advice has remained, in later years various TDD advocates have suggested that the
28+
function, method, or class under test is the "unit". Consider that if you don't feel like getting into a flame war on the internet, just don't use the word "unit" at all!
29+
30+
A "Mock" is a replacement class or method that is simpler to construct, easier to reason about, contains code for inspection of who called it with what arguments, and ideally is faster than the class or method it replaces.
31+
For example, writing tests of code that normally downloads files from an internet location, a Mock class will typically be implemented to fake those returns results so the tests don't require a network connection
32+
(and run more quickly and reliably). In Python most test writers use the `unittest.Mock.MagicMock` class to automatically generated any needed mock on the fly. In Google Test you can use the
33+
[`MOCK_METHOD`](https://google.github.io/googletest/reference/mocking.html) macro to achieve some of the same effect.
34+
35+
A "Fake" is similar to a mock, but typically doesn't bother with the introspection code, it is there simply to replace the existing class, but the test is not interested in how it is used. Rarely used in Python because
36+
of the ease of generating a Mock.
37+
38+
A "Stub" is a method that simply provides a canned answer for a given input. Sometimes instrumented, but often simply used to replace a more complex function with a simple, predictable response. For example, a random-number
39+
generator may be replaced with a function that simply returns "42" every time so that the results are deterministic (and therefore more easily testable).
40+
1841
## Python Testing
1942

2043
Most Python workbenches in FreeCAD already have at least a rudimentary test suite, so no additional cMake setup should be required beyond simply adding your test file(s) to the cMakeLists.txt file. In addition, in Python it is very easy

0 commit comments

Comments
 (0)