Hi.
So I heard somewhere that testing your code is a good idea.

In my project I am using CMake with visual studio 2015.

I found out how to add my QT Tests to my project, using CMake, though it wasn't easy.

My problem is that when a tests fails, it causes CTest itself to fail:


1> Test project C:/work/foo/build/msvc2015_64
1> Start 1: foo
1> 1/1 Test #1: foo...............***Failed 0.05 sec
1>
1> 0% tests passed, 1 tests failed out of 1
1>
1> Total Test time (real) = 0.06 sec
1>
1> The following tests FAILED:
1> 1 - foo(Failed)
1> Errors while running CTest
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cp pCommon.targets(133,5): error MSB3073: The command "setlocal
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cp pCommon.targets(133,5): error MSB3073: "C:\Program Files\CMake\bin\ctest.exe" --force-new-ctest-process -C Debug
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cp pCommon.targets(133,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cp pCommon.targets(133,5): error MSB3073: :cmEnd
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cp pCommon.targets(133,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cp pCommon.targets(133,5): error MSB3073: :cmErrorLevel
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cp pCommon.targets(133,5): error MSB3073: exit /b %1
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cp pCommon.targets(133,5): error MSB3073: :cmDone
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cp pCommon.targets(133,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cp pCommon.targets(133,5): error MSB3073: :VCEnd" exited with code 8.

If no tests fail, then there is no problem.

The test fails:

Qt Code:
  1. void TestSignals::testgetName() {
  2. QCOMPARE(s.getName(), "dfsdf ");
  3. }
  4.  
  5. QTEST_MAIN(TestSignals);
To copy to clipboard, switch view to plain text mode 

The test passes:

Qt Code:
  1. void TestSignals::testgetName() {
  2. QCOMPARE(s.getName(), "");
  3. }
  4.  
  5. QTEST_MAIN(TestSignals);
To copy to clipboard, switch view to plain text mode 

Another problem is, that I don't get any diagnostics. In the documentation it states that QCOMPARE should give a more descriptive error message, but as you can see, I get nothing.

I suppose the missing messages are caused by the fact that CTest fails. Is there a way to make CTest not fail just because a test fails?

Best Regards
DAVC