Skip to content

Commit 5cf5bbb

Browse files
AlesKusthomas-bc
andauthored
Update instructions for UT creation (#102)
* Update instructions for UT creation * Remove unecessary step --------- Co-authored-by: Thomas Boyer-Chammard <49786685+thomas-bc@users.noreply.github.com>
1 parent 8b98e0b commit 5cf5bbb

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

docs/led-blinker.md

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -761,17 +761,7 @@ This exercise will walk through development of basic unit tests for the `Led` co
761761

762762
To start off, use `fprime-util` to generate a unit test outline for the `Led` component.
763763

764-
First, register unit tests for the `Led` component with the build system by adding these lines at the very end of the component `CMakeLists.txt` file in your `led-blinker/Components/Led` directory, **after** the `register_fprime_module()` call.
765-
766-
```
767-
set(UT_SOURCE_FILES
768-
"${CMAKE_CURRENT_LIST_DIR}/Led.fpp"
769-
)
770-
set(UT_AUTO_HELPERS ON) # Additional Unit-Test autocoding
771-
register_fprime_ut()
772-
```
773-
774-
Next, generate a unit test build cache by running the following terminal commands:
764+
First, generate a unit test build cache by running the following terminal commands:
775765

776766
```shell
777767
#In led-blinker/Components/Led
@@ -780,7 +770,6 @@ fprime-util generate --ut
780770
> [!NOTE]
781771
> Unit tests run with special build settings and as such need their own build cache generated.
782772
783-
784773
Next we will generate unit test template files. This is similar to the component implementations we have run, but will set up the complete unit test harness.
785774

786775
To do so, run the implementation command in the terminal within your `led-blinker/Components/Led` directory:
@@ -789,24 +778,29 @@ To do so, run the implementation command in the terminal within your `led-blinke
789778
fprime-util impl --ut
790779
```
791780

792-
This step should create the files `LedTester.cpp`, `LedTester.hpp`, and `LedTestMain.cpp` in your current directory. Move them to a new subdirectory called `test/ut`.
781+
This step should create the files `LedTester.template.cpp`, `LedTester.template.hpp`, and `LedTestMain.template.cpp` in `led-blinker/Components/Led/test/ut`.
793782

794-
This is done with:
795-
```shell
796-
#In led-blinker/Components/Led
797-
mkdir -p test/ut
798-
mv LedTest* test/ut/
783+
Since this is the start of the test's implementation, we use the generated template files for our initial test implementation. Inside your `led-blinker/Components/Led/test/ut` directory, rename the files removing the `.template` suffix:
784+
785+
```bash
786+
# In led-blinker/Components/Led/test/ut
787+
mv LedTester.template.hpp LedTester.hpp
788+
mv LedTester.template.cpp LedTester.cpp
789+
mv LedTestMain.template.cpp LedTestMain.cpp
799790
```
800791

801-
Next, update the `CMakeLists.txt` file in your `led-blinker/Components/Led` directory to add those files to the list of unit-test source files. That section should look like this:
792+
Then, register the unit test files with the build system by uncommenting these lines at the very end of the component `CMakeLists.txt` file in your `led-blinker/Components/Led` directory:
802793

803794
```cmake
804795
set(UT_SOURCE_FILES
805-
"${CMAKE_CURRENT_LIST_DIR}/Led.fpp"
806-
"${CMAKE_CURRENT_LIST_DIR}/test/ut/LedTestMain.cpp"
807-
"${CMAKE_CURRENT_LIST_DIR}/test/ut/LedTester.cpp"
796+
"${CMAKE_CURRENT_LIST_DIR}/Led.fpp"
797+
"${CMAKE_CURRENT_LIST_DIR}/test/ut/LedTestMain.cpp"
798+
"${CMAKE_CURRENT_LIST_DIR}/test/ut/LedTester.cpp"
799+
)
800+
set(UT_MOD_DEPS
801+
STest
808802
)
809-
set(UT_AUTO_HELPERS ON) # Additional Unit-Test autocoding
803+
set(UT_AUTO_HELPERS ON)
810804
register_fprime_ut()
811805
```
812806

0 commit comments

Comments
 (0)