Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify namespace/class in VS2019 Test Explorer while using CTest/CMake

I'm using CMake + VS2019. In my test definition I have something like:

add_test(NAME "common/base64" COMMAND my_unit_test "common/base64")

VS2019 displays this like:

enter image description here

In project I have hundreds of tests and it is very inconvenient to search through unclear randomly generated names, expanding each items. So my questions:

  • How can I specify recognizable test name (instead of EBF.Tests.52488745200006951440) ?
  • How to specify namespace / class?

Also I can see Vs2019 Test Explorer can group by "Traits" - may be I can specify it over this feature?

like image 856
Dewfy Avatar asked Mar 04 '20 07:03

Dewfy


People also ask

Is CTest a part of CMake?

When you run the tests from your build environment, what really happens is that the build environment runs CTest . CTest is an executable that comes with CMake; it handles running the tests for the project. While CTest works well with CMake, you do not have to use CMake in order to use CTest.

How do I use test Explorer code in Visual Studio?

Tests can be run from Test Explorer by right-clicking in the code editor on a test and selecting Run test or by using the default Test Explorer shortcuts in Visual Studio. Some of the shortcuts are context-based. This means that they run or debug tests based on where your cursor is in the code editor.

What is CMake CTest?

Description. The ctest executable is the CMake test driver program. CMake-generated build trees created for projects that use the enable_testing() and add_test() commands have testing support. This program will run the tests and report results.


1 Answers

It seems that the "EBF.Tests" prefix is the "project name".

You can disable the test prefix or set a new one by altering the TEST_PREFIX setting in your test autodiscovery method or the test naming itself.

For CTest, by altering the test naming:

# use [namespace].[class].[testname] naming 
add_test("lib.namespace.Tests.SomeTest" test_exe)

For Catch2, by altering the test name prefixing by changing TEST_PREFIX in the auto-discovery method:

catch_discover_tests(
    TagTestsTarget
    TEST_SPEC "[tag]"                   # select tests by tag name
    TEST_PREFIX "lib.namespace.Tests."  # last dot required !
)
like image 155
Jens A. Koch Avatar answered Oct 21 '22 17:10

Jens A. Koch