Tests
As from 2.1, the test
command is supported.
The plugin does not support text output of the tests but generates everything into JSON format and then converts that to JUnit XML and produces a basic HTML report.
Layout
The task reacts to files in the source set’s root which match the patterns '*.tftest.hcl', '\*.tftest.json', '*.tofutest.hcl', '\*.tofutest.json'
.
It also looks for files in a test subdirectory, which by default, is called test
.
Configuration
opentofu {
sourceSets {
main {
executionOptions {
testing {
verbose = true (1)
}
}
testSubdir = 'testing' (2)
}
}
}
1 | Whether to include the plan and state for each test run.
Equivalent of passing -verbose to tofu on the command-line.
Default is false . |
2 | Override the default test directory. Default, by convention, is `test. |
Test filters
Pass --filter
on the Gradle command-line one or more times to specify tests that should be executed.
$ ./gradlew tofuTest --filter test/mytest.tofutest.hcl
Check lifecycle
These test tasks are not run as part of the check
lifecycle by default.
The reason is that infrastructure tests are very specific to the context of the organisation where they are being used.
You can use tofuTestAll
to run all your tests.
If you want it to be part of the check
lifecycle, then simply add
tasks.named('check') {
dependsOn('tofuTestAll')
}