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: technical/automated_testing.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ layout: default
4
4
5
5
# Automated Testing
6
6
7
-
FreeCAD uses two different automated testing mechanisms, depending on the language being tested. The oldest, and most well-used test framework is the Python `unittest` system, which hooks directly into the FreeCAD Test Workbench. The second is the standalone Google Test C++ testing framework, which generates individual executables fo each part of the test suite.
7
+
FreeCAD uses two different automated testing mechanisms, depending on the language being tested. The oldest, and most well-used test framework is the Python `unittest` system, which hooks directly into the FreeCAD Test Workbench, but can only test Python code (and Python wrappers to C++ code). The second is the standalone Google Test C++ testing framework, which generates individual executables for each part of the test suite, and is used to directly test C++ code without having to wrap it in Python.
8
8
9
9
## References
10
10
@@ -42,7 +42,7 @@ generator may be replaced with a function that simply returns "42" every time so
42
42
## Python Testing
43
43
44
44
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
45
-
to create Mock functions and objects to reduce the dependency on external code, and/or to ensure you are testing only the isolated bit of code that you mean to. A typical Python unit test file might look like this:
45
+
to create Mock functions and objects to reduce the dependency on external code, and/or to ensure you are testing only the isolated bit of code that you mean to. A typical Python test file might look like this:
46
46
```python
47
47
# SPDX-License-Identifier: LGPL-2.1-or-later
48
48
@@ -78,7 +78,7 @@ class TestVersion(unittest.TestCase):
78
78
os.unlink(temp.name)
79
79
```
80
80
81
-
If you are developing a FreeCAD module, place the above in a file inside your module, and register your unit test with FreeCAD's Test Workbench by adding this in your Init.py file:
81
+
If you are developing a FreeCAD module, place the above in a file inside your module, and register your test with FreeCAD's Test Workbench by adding this in your Init.py file:
82
82
83
83
```
84
84
FreeCAD.__unit_test__ += ["my_file"]
@@ -92,7 +92,7 @@ FreeCAD -t my_file
92
92
93
93
## C++ Testing
94
94
95
-
In an ideal world, a C++ unit test would be perfectly isolated from any external dependencies, which would be replaced with minimal, instrumented "mock" versions of themselves. However,
95
+
In an ideal world, a C++ test would be perfectly isolated from any external dependencies, which would be replaced with minimal, instrumented "mock" versions of themselves. However,
96
96
this almost always requires that the code under test has been *designed* for testing, which is usually not the case for our existing code. In many cases you must add tests for the existing
97
97
functionality and implementation, with all its deficiencies, before you can begin to refactor the code to make the tests better. There are many strategies for doing those "dependency injections",
98
98
and over time we aspire to refactor FreeCAD such that it is possible, but developers are also encouraged to remember that:
@@ -105,8 +105,10 @@ of the code (though sometimes that "functionality" is encompassed by multiple fu
105
105
themselves be "under test" it is critical that they be as short, simple, and self-explanatory as possible. A common idiom to use is "Arrange-Act-Assert", which in our test
106
106
framework looks like this:
107
107
```c++
108
-
// ??? App/AppTests/MappedNamePOSTFIXTEST.cpp ???
109
-
// TEST(ClassName, methodName)
108
+
// TEST(ClassName, testMethodName), where "testMethodName" is some desciptive indication
109
+
// of what is being tested. In simple cases in may simply be the name of the method being
110
+
// tested. In more complex cases, it may be a longer statement of the input and expected
111
+
// test result (e.g. `toConstStringWithBadDataThrowsException`)
0 commit comments