Merge pull request #8153 from lorjala/unittests-autoname

Unit tests: automatic unit test suite naming
pull/8096/head
Martin Kojtal 2018-09-20 09:29:02 +02:00 committed by GitHub
commit 6c348024cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 13 additions and 61 deletions

View File

@ -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)
@ -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")

View File

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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -3,9 +3,6 @@
# UNIT TESTS
####################
# Unit test suite name
set(TEST_SUITE_NAME "platform-CircularBuffer")
set(unittest-sources
)

View File

@ -3,9 +3,6 @@
# UNIT TESTS
####################
# Unit test suite name
set(TEST_SUITE_NAME "suitename")
set(unittest-includes ${unittest-includes}
headerfile
)

View File

@ -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",
"",
@ -41,7 +41,6 @@ class UnitTestGeneratorTool(object):
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
@ -111,7 +110,6 @@ class UnitTestGeneratorTool(object):
content = self._replace_content(template_content,
dir_name,
class_name,
suite_name,
file_extension)
output_file.writelines(content)
@ -130,7 +128,6 @@ class UnitTestGeneratorTool(object):
content = self._replace_content(template_content,
dir_name,
class_name,
suite_name,
file_extension)
output_file.writelines(content)