Skip to content

Commit 1b974d5

Browse files
authored
Merge pull request #9700 from Geometror/tests-add-subcases-section
Add section about subcases to the unit testing guide
2 parents 5f7da09 + 012805b commit 1b974d5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

contributing/development/core_and_modules/unit_testing.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,26 @@ common test data for each test, or writing parameterized tests.
152152
Godot supports writing tests per C++ module. For instructions on how to write
153153
module tests, refer to :ref:`doc_custom_module_unit_tests`.
154154

155+
Subcases
156+
~~~~~~~~
157+
158+
In situations where you have a common setup for several test cases with only slight variations, subcases can be very helpful. Here's an example:
159+
160+
.. code-block:: cpp
161+
162+
TEST_CASE("[SceneTree][Node] Testing node operations with a very simple scene tree") {
163+
// ... common setup (e.g. creating a scene tree with a few nodes)
164+
SUBCASE("Move node to specific index") {
165+
// ... setup and checks for moving a node
166+
}
167+
SUBCASE("Remove node at specific index") {
168+
// ... setup and checks for removing a node
169+
}
170+
}
171+
172+
Each ``SUBCASE`` causes the ``TEST_CASE`` to be executed from the beginning.
173+
Subcases can be nested to an arbitrary depth, but it is advised to limit nesting to no more than one level deep.
174+
155175
Assertions
156176
~~~~~~~~~~
157177

0 commit comments

Comments
 (0)