Mat
Mat

Reputation: 1009

CTest: Test not available without configuration

I realize this is a very basic question, but I was unable to fix my problem despite even after reading multiple tutorials, including the official tutorial and the Professional Cmake book.

I am simply trying to add unit tests to my C++ project with CMake 3.28 on Visual Studio 2022. However, when I run CTest, I get the following error:

Test not available without configuration.  (Missing "-C <config>"?)
1/1 Test #1: cpp_test .........................***Not Run   0.00 sec

The "Test not available without configuration" message seems to indicate the configuration is missing. I did however defined the test in my CMakeLists.txt.

I recreated the problem with minimal code.

main.ccp

int main()
{
    return 0;
}

cpp_test.cpp

int main()
{
    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.28.0)

project("myproject")

add_executable (CMakeProject1 "main.cpp")

add_executable(cpp_test cpp_test.cpp)
enable_testing()
add_test(NAME cpp_test COMMAND $<TARGET_FILE:cpp_test>)

All files are located in the same folder.

When I run the following commands:

cmake -S . -B build
cd build
cmake --build .
ctest . --rerun-failed --output-on-failure

I get the error:

Test project C:/Users/…/source/repos/CMakeProject1/CMakeProject1/build
    Start 1: cpp_test
Test not available without configuration.  (Missing "-C <config>"?)
1/1 Test #1: cpp_test .........................***Not Run   0.00 sec

0% tests passed, 1 tests failed out of 1

Total Test time (real) =   0.02 sec

The following tests FAILED:
          1 - cpp_test (Not Run)
Errors while running CTest

Upvotes: 1

Views: 912

Answers (1)

CaptainOnly
CaptainOnly

Reputation: 83

As @Tsyvarev mentioned in the comments, a configuration is required when using multi-configuration generators like Visual Studio. In that case, add the configuration you want the test to run in (.e.g -C Debug)

Upvotes: 1

Related Questions