Testing in the native ecosystem takes many forms.
There are different testing libraries and frameworks, as well as many different types of test. All need to be part of the build, whether they are executed frequently or infrequently. This chapter is dedicated to explaining how Gradle handles differing requirements between and within builds, with significant coverage of how it integrates with the executable-based testing frameworks, such as Google Test.
But first, we look at the basics of native testing in Gradle.
All C++ testing revolves around a single task type: RunTestExecutable. This runs a single test executable built with any testing framework and asserts the execution was successful using the exit code of the executable. The test case results aren’t collected and no reports are generated.
In order to operate, the RunTestExecutable task type requires just one piece of information:
Where to find the built test executable (property: RunTestExecutable.getExecutable())
When you’re using the C++ Unit Test Plugin you will automatically get the following:
The test plugins configure the required pieces of information appropriately.
In addition, they attach the
run task to the
check lifecycle task.
They also create the
testImplementation dependency configuration. Dependencies that are only needed for test compilation, linking and runtime may be added to this configuration.
unitTest script block behave similarly to a
application script block.
The RunTestExecutable task has many configuration options. We cover a number of them in the rest of the chapter.
Gradle executes tests in a separate (‘forked’) process.
You can control how the test process is launched via several properties on the RunTestExecutable task, including the following:
ignoreFailures- default: false
If this property is
true, Gradle will continue with the project’s build once the tests have completed, even if some of them have failed. Note that, by default, RunTestExecutable task type always executes every test that it detects, irrespective of this setting.
See RunTestExecutable for details on all the available configuration options.