diff --git a/docs/Tutorials/MathComponent/MathReceiver/test/ut/main.cpp b/docs/Tutorials/MathComponent/MathReceiver/test/ut/TestMain.cpp similarity index 100% rename from docs/Tutorials/MathComponent/MathReceiver/test/ut/main.cpp rename to docs/Tutorials/MathComponent/MathReceiver/test/ut/TestMain.cpp diff --git a/docs/Tutorials/MathComponent/MathSender/test/ut/main.cpp b/docs/Tutorials/MathComponent/MathSender/test/ut/TestMain.cpp similarity index 100% rename from docs/Tutorials/MathComponent/MathSender/test/ut/main.cpp rename to docs/Tutorials/MathComponent/MathSender/test/ut/TestMain.cpp diff --git a/docs/Tutorials/MathComponent/Tutorial.md b/docs/Tutorials/MathComponent/Tutorial.md index 9432be3203..94c0b176c2 100644 --- a/docs/Tutorials/MathComponent/Tutorial.md +++ b/docs/Tutorials/MathComponent/Tutorial.md @@ -1085,19 +1085,19 @@ The files that are generated are: ``` Tester.hpp Tester.cpp -TesterBase.hpp -TesterBase.cpp -GTestBase.hpp -GTestBase.cpp +TestMain.cpp ``` +**Note:** TesterBase.* and GTestBase.* files can be removed. these will be regenerated when the unit test builds. + The functions of the files are: |File|Function| |---|---| -|TesterBase.*|Base class for test class. Defines necessary handlers as well as helper functions -|GTestBase.*|Helper class derived from TesterBase that has macros that use Google Test to test interfaces| +|TesterBase.*| Base class for test class. Defines necessary handlers as well as helper functions. **Autocoded** | +|GTestBase.*|Helper class derived from TesterBase that has macros that use Google Test to test interfaces. **Autocoded** | |Tester.*|Derived tester class that inherits from GTestBase. Includes instance of the component and helpers to connect ports| +|TestMain.cpp|Main unit test implementation file| Unit tests are built in subdirectories of the module, so the unit test file must be copied there. The build system supports a standard subdirectory of `test/ut` below the module being tested. While in the MathSender directory, create the `test/ut` directory: @@ -1121,10 +1121,8 @@ set(SOURCE_FILES register_fprime_module() set(UT_SOURCE_FILES - "${CMAKE_CURRENT_LIST_DIR}/test/ut/main.cpp" + "${CMAKE_CURRENT_LIST_DIR}/test/ut/TestMain.cpp" "${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp" - "${CMAKE_CURRENT_LIST_DIR}/test/ut/TesterBase.cpp" - "${CMAKE_CURRENT_LIST_DIR}/test/ut/GTestBase.cpp" ) register_fprime_ut() ``` @@ -1135,7 +1133,8 @@ A `UT_MODS` variable may be set should the UT depend on modules not automaticall ##### 2.4.1.3.2 Test Code Implementation -The `main.cpp` file must be added. For this test, it appears like this: +The unit tests must be added to `TestMain.cpp`. Change the default code to appear +like this: ```c++ #include "Tester.hpp" @@ -1164,7 +1163,6 @@ int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } - ``` F' uses the Google Test framework to run unit tests. For more information about the Google Test Framework see here: @@ -1228,7 +1226,7 @@ The test component is instantiated here: NameSpace::Tester tester; ``` -This allows the component to start from an newly initialized state for each unit test. +This allows the component to start from a newly initialized state for each unit test. The unit test is executed by calling a member function of the `tester` class: @@ -1236,6 +1234,9 @@ The unit test is executed by calling a member function of the `tester` class: tester.someUnitTestFunc(); ``` +> NOTE: The autogenerated `Tester.*` files include a placeholder "toDo" function. Feel +free to leave that in or delete it. + The `Tester.hpp` stub can be updated to include the declarations of the unit test functions: ```c++ @@ -1245,6 +1246,9 @@ The `Tester.hpp` stub can be updated to include the declarations of the unit tes // ---------------------------------------------------------------------- // Tests // ---------------------------------------------------------------------- + //! To do + //! + void toDo(void); //! Test operation command //! @@ -1275,7 +1279,7 @@ Add a member function to the implementation class in `Tester.cpp` to implement t this->sendCmd_MS_DO_MATH(0,10,1.0,2.0,MathSenderComponentBase::ADD); // retrieve the message from the message queue and dispatch the command to the handler this->component.doDispatch(); - // verify that that only one output port was called + // verify that only one output port was called ASSERT_FROM_PORT_HISTORY_SIZE(1); // verify that the math operation port was only called once ASSERT_from_mathOut_SIZE(1); @@ -1321,7 +1325,6 @@ Add a member function to the implementation class in `Tester.cpp` to implement t // verify the expected value of the event arguments ASSERT_EVENTS_MS_RESULT(0,10.0); } - ``` Some highlights are: