[native cpp] how do I use NativeTestSuiteBinarySpec?

(Ralf Schallenberg) #1


I want to add tests to our Gradle build using the C++ testing framework Catch. Can someone explain how to do this? I presume I need to use NativeTestSuiteBinarySpec somewhere, but I don’t know where.


(Carlos) #2

I am trying to do the same, that is my failed :sweat: attempt:

apply plugin: 'cpp'
apply plugin: TestingModelBasePlugin

model {
    components {
    testSuites {
        iocTest(NativeTestSuiteBinarySpec) {
            testing $.components.ioc
    binaries {
        all {
            if (toolChain in VisualCpp) {
                cppCompiler.args '/std:c++latest'
            } else {
                cppCompiler.args '-std=c++11'

task wrapper(type: Wrapper) {
    gradleVersion = '3.4.1'

This is my project structure:

  • ioc
  • cpp (project source files)
  • iocTest
  • cpp (test files + catch.hpp)

And this is the error I get:
Cannot create 'testSuites.iocTest' with type 'org.gradle.nativeplatform.test.NativeTestSuiteBinarySpec' as this is not a subtype of 'org.gradle.testing.base.TestSuiteSpec'.

(Daniel Lacasse) #3

Hi @RalfSchallenberg and @carlosvin,

Unfortunately, the model for native test suites has small gaps that prevent easy integration of newer test suite. Down the road, we are looking at providing a model to add custom test suite. At the moment, you could just create a plain NativeExecutableSpec and configure it accordingly.




@RalfSchallenberg and @carlosvin,

I recently had to do something similar. I’m not sure it will answer all of your questions, but I threw an example project up on GitHub: https://github.com/k-mack/cpp-testing/tree/master/gradle-catch. The README tries to describe the approach I took to getting Catch, GCOV, and LCOV working together using Gradle. Hopefully, you’ll find it helpful.