* fix Markdown issue 'Headers should be surrounded by blank lines' * fix MD012 * fix MD022 * fix MD026 * fix MD007 * fix MD032 * fix MD038 * fix MD040 * fix MD031 * fix MD034 * fix MD004 * fix new findings * fix MD036 * fix MD038 * fix MD032 * fix MD006
3.5 KiB
batsExecuteTests
Description
This step executes tests using the Bash Automated Testing System - bats-core
Prerequsites
You need to have a Bats test file. By default you would put this into directory src/test within your source code repository.
Parameters
| parameter | mandatory | default | possible values |
|---|---|---|---|
| script | yes | ||
| dockerImage | no | node:8-stretch |
|
| dockerWorkspace | no | /home/node |
|
| envVars | no | [:] |
|
| failOnError | no | false |
|
| gitBranch | no | ||
| gitSshKeyCredentialsId | no | ||
| outputFormat | no | junit |
tap |
| repository | no | https://github.com/bats-core/bats-core.git |
|
| stashContent | no | ['tests'] |
|
| testPackage | no | piper-bats |
|
| testPath | no | src/test |
|
| testRepository | no |
Details:
-
outputFormatdefines the format of the test result output.junitwould be the standard for automated build environments but you could use also the optiontap. -
For the transformation of the test result to xUnit format the node module tap-xunit is used.
dockerImageanddockerWorkspacedefine the Docker image used for the transformation andtestPackagedefines the name of the test package used in the xUnit result file. -
testPathdefines either the directory which contains the test files (*.bats) or a single file. You can find further details in the Bats-core documentation -
With
failOnErroryou can define the behavior, in case tests fail. For example, in case ofoutputFormat: 'junit'you should set it tofalse. Otherwise test results cannot be recorded using thetestsPublishhResultsstep afterwards. -
You can pass environment variables to the test execution by defining parameter
envVars.With
envVarsit is possible to pass either fixed values but also templates usingcommonPipelineEnvironment.Example:
batsExecuteTests script: this, envVars = [ FIX_VALUE: 'my fixed value', CONTAINER_NAME: '${commonPipelineEnvironment.configuration.steps.executeBatsTests.dockerContainerName}', IMAGE_NAME: '${return commonPipelineEnvironment.getDockerImageNameAndTag()}' ]This means within the test one could refer to environment variables by calling e.g.
run docker run --rm -i --name $CONTAINER_NAME --entrypoint /bin/bash $IMAGE_NAME echo "Test" -
Using parameters
testRepositorythe tests can be loaded from another reposirory. In case the tests are not located in the master branch the branch can be specified withgitBranch. For protected repositories you can also define the access credentials viagitSshKeyCredentialsId. Note: In case of using a protected repository,testRepositoryshould include the ssh link to the repository. -
The parameter
repositorydefines the version of bats-core to be used. By default we use the version from the master branch.
Step configuration
The following parameters can also be specified as step/stage/general parameters using the global configuration:
- dockerImage
- dockerWorkspace
- envVars
- failOnError
- gitBranch
- gitSshKeyCredentialsId
- outputFormat
- repository
- stashContent
- testPackage
- testPath
- testRepository
Example
batsExecuteTests script:this
testsPublishResults junit: [pattern: '**/Test-*.xml', archive: true]