Skip to content

Unit tests: automatic unit test suite naming #8153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions UNITTESTS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,17 @@ foreach(testfile ${unittest-file-list})
# Get source files
include("${testfile}")

if(TEST_SUITE_NAME)
set(TEST_SUITES ${TEST_SUITES} ${TEST_SUITE_NAME})
else()
message(FATAL_ERROR "No TEST_SUITE_NAME found in test file. Add it to ${testfile}.")
endif()
get_filename_component(TEST_SUITE_DIR ${testfile} DIRECTORY)

file(RELATIVE_PATH
TEST_SUITE_NAME # output
${PROJECT_SOURCE_DIR} # root
${TEST_SUITE_DIR} #abs dirpath
)

string(REGEX REPLACE "/|\\\\" "-" TEST_SUITE_NAME ${TEST_SUITE_NAME})

set(TEST_SUITES ${TEST_SUITES} ${TEST_SUITE_NAME})

set(LIBS_TO_BE_LINKED gmock_main)

Expand All @@ -178,7 +184,7 @@ foreach(testfile ${unittest-file-list})
# Link the executable with the libraries.
target_link_libraries(${TEST_SUITE_NAME} ${LIBS_TO_BE_LINKED})

add_test(NAME "${TEST_SUITE_NAME}UnitTests" COMMAND ${TEST_SUITE_NAME})
add_test(NAME "${TEST_SUITE_NAME}" COMMAND ${TEST_SUITE_NAME})

# Append test build directory to list
list(APPEND BUILD_DIRECTORIES "./CMakeFiles/${TEST_SUITE_NAME}.dir")
Expand Down
3 changes: 0 additions & 3 deletions UNITTESTS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ Each class to be tested requires two files for unit testing:

A unit test definition file `unittest.cmake` requires variables to be set for a test to be configured. File source paths in `unittest.cmake` files need to be relative to the unit test folder and `CMakeLists.txt`.

* **TEST_SUITE_NAME** - Identifier for the test suite. Use naming convention *PATH_TO_THE_TESTABLE_FILE* e.g. *features-netsocket-InternetSocket*
* **unittest-includes** - Include paths for headers needed to build the tests in addition to the base include paths listed in [CMakeLists.txt](CMakeLists.txt). Optional.
* **unittest-sources** - Mbed OS source files and stubs included for the build.
* **unittest-test-sources** - Unit test source files.
Expand All @@ -225,8 +224,6 @@ For example to create a unit test for `rtos/Semaphore.cpp`:
1. Create a directory for unit test files in `UNITTESTS/rtos/Semaphore`.
2. Create a test definition file `UNITTESTS/rtos/Semaphore/unittest.cmake` with the following content:
```
set(TEST_SUITE_NAME "rtos-Semaphore")

set(unittest-sources
stubs/mbed_assert.c
../rtos/Semaphore.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# UNIT TESTS
####################

# Unit test suite name
set(TEST_SUITE_NAME "cellular-framework-AT-AT_CellularBase")

# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/AT/AT_CellularBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# UNIT TESTS
####################

# Unit test suite name
set(TEST_SUITE_NAME "at_cellular_device_unit")

# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# UNIT TESTS
####################

# Unit test suite name
set(TEST_SUITE_NAME "at_cellular_information_unit")

# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# UNIT TESTS
####################

# Unit test suite name
set(TEST_SUITE_NAME "at_cellular_network_unit")

# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# UNIT TESTS
####################

# Unit test suite name
set(TEST_SUITE_NAME "at_cellular_power_unit")

# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# UNIT TESTS
####################

# Unit test suite name
set(TEST_SUITE_NAME "at_cellular_sim_unit")

# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# UNIT TESTS
####################

# Unit test suite name
set(TEST_SUITE_NAME "at_cellular_sms_unit")

# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# UNIT TESTS
####################

# Unit test suite name
set(TEST_SUITE_NAME "at_cellular_stack_unit")

# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# UNIT TESTS
####################

# Unit test suite name
set(TEST_SUITE_NAME "at_handler_unit")

# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# UNIT TESTS
####################

# Unit test suite name
set(TEST_SUITE_NAME "cellular-framework-common-util")

# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
Expand Down
3 changes: 0 additions & 3 deletions UNITTESTS/features/netsocket/InternetSocket/unittest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# UNIT TESTS
####################

# Unit test suite name
set(TEST_SUITE_NAME "features-netsocket-InternetSocket")

set(unittest-sources
../features/netsocket/SocketAddress.cpp
../features/netsocket/NetworkStack.cpp
Expand Down
3 changes: 0 additions & 3 deletions UNITTESTS/features/netsocket/NetworkInterface/unittest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# UNIT TESTS
####################

# Unit test suite name
set(TEST_SUITE_NAME "features-netsocket-NetworkInterface")

# Source files
set(unittest-sources
../features/netsocket/NetworkInterface.cpp
Expand Down
3 changes: 0 additions & 3 deletions UNITTESTS/features/netsocket/TCPSocket/unittest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# UNIT TESTS
####################

# Unit test suite name
set(TEST_SUITE_NAME "features-netsocket-TCPSocket")

set(unittest-sources
../features/netsocket/SocketAddress.cpp
../features/netsocket/InternetSocket.cpp
Expand Down
3 changes: 0 additions & 3 deletions UNITTESTS/features/netsocket/UDPSocket/unittest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# UNIT TESTS
####################

# Unit test suite name
set(TEST_SUITE_NAME "features-netsocket-UDPSocket")

set(unittest-sources
../features/netsocket/SocketAddress.cpp
../features/netsocket/NetworkStack.cpp
Expand Down
3 changes: 0 additions & 3 deletions UNITTESTS/platform/CircularBuffer/unittest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# UNIT TESTS
####################

# Unit test suite name
set(TEST_SUITE_NAME "platform-CircularBuffer")

set(unittest-sources
)

Expand Down
3 changes: 0 additions & 3 deletions UNITTESTS/template/unittest.cmake.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# UNIT TESTS
####################

# Unit test suite name
set(TEST_SUITE_NAME "suitename")

set(unittest-includes ${unittest-includes}
headerfile
)
Expand Down
5 changes: 1 addition & 4 deletions UNITTESTS/unit_test/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class UnitTestGeneratorTool(object):
Generator tool to create new unit tests from template
"""

def _replace_content(self, template_content, dirname, classname, suite_name, extension):
def _replace_content(self, template_content, dirname, classname, extension):
if extension == "h":
content = re.sub(r"cppfile",
"",
Expand All @@ -41,7 +41,6 @@ def _replace_content(self, template_content, dirname, classname, suite_name, ext
content = re.sub(r"headerfile", "../dirname/template.h", content)
content = re.sub(r"dirname", dirname, content)
content = re.sub(r"template", classname, content)
content = re.sub(r"suitename", suite_name, content)

return content

Expand Down Expand Up @@ -111,7 +110,6 @@ def create(self, mbed_os_root=None, filepath=None):
content = self._replace_content(template_content,
dir_name,
class_name,
suite_name,
file_extension)

output_file.writelines(content)
Expand All @@ -130,7 +128,6 @@ def create(self, mbed_os_root=None, filepath=None):
content = self._replace_content(template_content,
dir_name,
class_name,
suite_name,
file_extension)

output_file.writelines(content)
Expand Down