Skip to content

Commit df9cd02

Browse files
authored
Expand on test naming
1 parent 685924e commit df9cd02

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

technical/automated_testing.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ layout: default
44

55
# Automated Testing
66

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.
88

99
## References
1010

@@ -42,7 +42,7 @@ generator may be replaced with a function that simply returns "42" every time so
4242
## Python Testing
4343

4444
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:
4646
```python
4747
# SPDX-License-Identifier: LGPL-2.1-or-later
4848

@@ -78,7 +78,7 @@ class TestVersion(unittest.TestCase):
7878
os.unlink(temp.name)
7979
```
8080

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:
8282

8383
```
8484
FreeCAD.__unit_test__ += ["my_file"]
@@ -92,7 +92,7 @@ FreeCAD -t my_file
9292

9393
## C++ Testing
9494

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,
9696
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
9797
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",
9898
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
105105
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
106106
framework looks like this:
107107
```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`)
110112
TEST(MappedName, toConstString)
111113
{
112114
// Arrange

0 commit comments

Comments
 (0)