Skip to main content

C/C++

The following sections provide information on using Testspace with popular C/C++ test frameworks and tools.

To push collected files simply use the Testspace client:

$ testspace static-analysis-results test-results code-coverage-results

Test Frameworks

Catch

Catch is a multi-paradigm automated test framework for C++.

Testspace accepts JUnit XML formatted Catch application results. Here is an example of how to produce such:

$TEST_DIR/application-name -r junit -o results.xml

In the Testspace client command-line reference results.xml as "test-results" file.

CppUTest

CppUTest is a unit testing and mocking framework for C/C++.

C++ CppUTest sample: https://github.com/testspace-samples/cpp.cpputest

Testspace accepts JUnit XML formatted CppUTest application results. Here is an example of how to produce such:

$TEST_DIR/application-name -o junit

In the Testspace client command-line reference cpputest_*.xml as "test-results" files.

CTest

CTest is a testing tool distributed as a part of CMake for executing test binaries.

Testspace accepts CTest XML formatted CTest results. Here is an example of how to produce such:

ctest --no-compress-output -T Test

In the Testspace client command-line reference Test.xml as "test-results" file.

Google Test

Google Test is a unit testing framework for C++.

C++ Google Test sample: https://github.com/testspace-samples/cpp.googletest

Testspace accepts JUnit XML formatted Google Test application results. Here is an example of how to produce such:

$TEST_DIR/sample1_unittest --gtest_output=xml:sample1.xml
$TEST_DIR/sample2_unittest --gtest_output=xml:sample2.xml
$TEST_DIR/sample3_unittest --gtest_output=xml:sample3.xml
$TEST_DIR/sample4_unittest --gtest_output=xml:sample4.xml

In the Testspace client command-line reference sample*.xml as "test-results" files.

Microsoft Unit Test Framework

Microsoft unit test framework is installed with Visual Studio and provides a framework for testing unmanaged code written in C++.

Testspace accepts TRX formatted Microsoft Unit Test assembly results. Here is an example of how to produce such using vstest.console:1

vstest.console %TEST_DIR%\test-assembly.dll /Logger:trx

In the Testspace client command-line reference TestResults\*.trx as "test-results" files.

Code Coverage

BullseyeCoverage

BullseyeCoverage is a C++ code coverage analyzer used to improve the quality of software.

Testspace accepts Bullseye XML formatted results. Bullseye does not produce this natively, however it provides covxml, a command line utility, that converts a native bullseye data file to the desired XML Report. Here is an example of how to produce such:

covxml -f bullseye.cov -o coverage.xml

In the Testspace client command-line reference coverage.xml as "code-coverage-results" file.

Note, if desired you could annotate the Testspace created special Code Coverage suite with the native bullseye coverage file (i.e. bullseye.cov). That way it can be downloaded from published Results and used with the Bullseye Coverage Browser:

testspace coverage.xml "[Code Coverage]+bullseye.cov{Bullseye native file}"

Gcov/llvm-cov

Gcov and llvm-cov are tools you can use in conjunction with GCC and Clang to test code coverage in your programs.

Note: The description that follows assumes that you are using GCC or Clang to compile/link your source code instrumented for coverage analysis.

Testspace accepts Cobertura XML formatted results. Gcov/llvm-gov does not produce this natively, however there are several widely adopted utilities that could be used to interpret the native gcov data files and generate the desired XML Report. Here is couple of examples of how to produce such:

using gcovr, a utility for managing the use of the GNU gcov

gcovr --cobertura -o coverage.xml

using LCOV, a GNU gcov extension tool, in combination with a lcov to Cobertura XML Converter

lcov --rc lcov_branch_coverage=1 -c -o temp.info
python lcov_cobertura.py temp.info -o coverage.xml

In the Testspace client command-line reference coverage.xml as "code-coverage-results" file.

OpenCppCoverage

OpenCppCoverage is an open source code coverage tool for C++ under Windows.

Testspace accepts Cobertura XML formatted results. Here is an example of how to produce such:

OpenCppCoverage --sources=\path\to\source --export_type=cobertura:coverage.xml -- test-app.exe

In the Testspace client command-line reference coverage.xml as "code-coverage-results" file.

Visual Studio Coverage

Visual Studio Coverage is provided as part of the Microsoft unit test framework.

Testspace accepts BINARY or XML formatted Visual Studio Coverage results. Here is an example of how to produce such:

vstest.console %TEST_DIR%\test-assembly.dll /Logger:trx /EnableCodeCoverage

In the Testspace client command-line reference *.coverage as "code-coverage-results" files.

Static Analysis

Compiler

Any compiler relies on static analysis of the source code during compilation to generate its errors and warnings.

Testspace accepts GCC/Emacs or Visual Studio style formatted build output logs. Simply write your build output to a file, e.g. build.log.

In the Testspace client command-line reference build.log{lint} as "static-analysis-results" file.

Cppcheck

Cppcheck is a static analysis tool for C/C++ code.

Testspace accepts Cppcheck XML formatted results. Here is an example of how to produce such:

cppcheck --xml-version=2 /path/to/source > analysis.xml

In the Testspace client command-line reference analysis.xml as "static-analysis-results" file.

CPPLint

CPPLint is the Google's C++ style guide code checker.

Testspace accepts Visual Studio style formatted output logs. Simply write your analysis output to a file:

./cpplint.py /path/to/source 2>&1 > analysis.log

In the Testspace client command-line reference analysis.log{lint} as "static-analysis-results" file.

Klocwork

Klocwork is a static code analysis tool for C/C++, Java, and C#.

Testspace accepts Klocwork XML formatted results. Here is an example of how to produce such:

kwcheck list -F xml --report analysis.xml /path/to/source
kwcheck run -F xml --report analysis.xml /path/to/source

In the Testspace client command-line reference analysis.xml as "static-analysis-results" file.

OCLint

OCLint is a static code analysis tool for improving quality and reducing defects by inspecting C, C++ and Objective-C code.

Testspace accepts PMD XML formatted results. Here is an example of how to produce such:

oclint -report-type pmd -o analysis.xml /path/to/source

In the Testspace client command-line reference analysis.xml as "static-analysis-results" file.

PC-lint

PC-lint is a static analysis tool for C/C++ source code.

Testspace accepts Visual Studio style formatted output logs. Here is an example of how to produce such:

Lint-nt +ffn -width(0) -hf1 -format="%f(%l): %t %n: %m" -os(analysis.log) /path/to/source

In the Testspace client command-line reference analysis.log{lint} as "static-analysis-results" file.

Vera++

Vera++ is a programmable tool for verification, analysis and transformation of C++ source code.

Testspace accepts Checkstyle XML formatted results. Here is an example of how to produce such:

vera++ --checkstyle-report analysis.xml /path/to/source

In the Testspace client command-line reference analysis.xml as "static-analysis-results" file.

Visual Studio PREfast

Visual Studio PREfast is the Microsoft's native C/C++ code analysis tool.

Testspace accepts Visual Studio PREfast XML formatted results. Here is an example of how to produce such:

msbuild <vcxprojectfile> /p:Configuration=config-name /p:Platform=platform-name /p:RunCodeAnalysisOnce=True

In the Testspace client command-line reference config-name\platform-name\vc.nativecodeanalysis.all.xml as "static-analysis-results" file.

Alternatively the actual build log could be used - besides compiler errors/warnings it also contains the static analysis output. Simply write your build output to a file:

msbuild <vcxprojectfile> /p:Configuration=config-name /p:Platform=platform-name /p:RunCodeAnalysisOnce=True /flp:LogFile=build.log;Encoding=utf-8

In the Testspace client command-line reference build.log{lint} as "static-analysis-results" file.


  1. Depending on the version of Visual Studio there are different test runners available.