ec-specs is a specification and acceptance testing framework based on Spock and CloudBees CD/RO DSL. This repository includes example specifications for testing sample CloudBees CD/RO releases, pipelines, DSL scripts, etc. Additionally, a Maven pom.xml is included for building and running example specifications.
- JDK 17 or higher
- Maven version 3.8.6 or higher
- CloudBees CD/RO v2023.10.0 or higher test environment
NOTE: The CloudBees CD/RO server can be running locally, on a remote server, or in a Kubernetes cluster.
To compile ec-spec, run:
mvn compile
This command downloads the com.electriccloud.commander-spec-tests-core.jar from a CloudBees Maven repository.
NOTE: If you encounter a
[ERROR] 503 Service Temporarily Unavailablemessage while attempting to download the dependencies, it may be caused by CloudBees migrating the JAR to a dedicated Maven repository to address security issues. To resovle this issue:
- Run
git pullon theec-specs-examplesrepository. This updates the JAR archive path.- Follow the instructions to compile tests again.
This downloads the dependencies again and should resolve the issue.
After you have installed a test instance of CloudBees CD/RO, to run the spec tests:
- For a CloudBees CD/RO server running on a
localhostwith the default password foradminuser:mvn test - For the CloudBees CD/RO server running on a remote server, for example
test-remote-server, using user credentialstest-user/test-user-password:mvn -DCOMMANDER_SERVER=test-remote-server -DCOMMANDER_USER=test-user -DCOMMANDER_PASSWORD=test-user-password test
Spock allows you to write specifications that describe expected features exhibited by a system. An ec-specs specification is a Groovy class with a naming pattern <YOUR-CUSTOM>Spec that extends from com.electriccloud.spec.SpockTestSupport, which extends from spock.lang.Specification.
The following is an example of a simple specification class:
import com.electriccloud.spec.SpockTestSupport
class MySpec extends SpockTestSupport {
def "my dsl works as expected"() {
given: 'a project'
// Use a random name for the project to ensure the test is isolated from other feature method runs.
def args = [projectName: randomize ('myproj')]
dsl "project args.projectName", args
when: 'an application is created using the given dsl'
def result = dsl "application 'myapp', projectName: args.projectName ", args
then: 'the application creation is successful'
result.application.projectName == args.projectName
cleanup:
// Clean up after the feature method run.
deleteProjects(args)
}
def "another test"() {
//...
}
}MySpeccontains two feature methods:my dsl works as expectedanother test
- Before the feature methods in
MySpecrun, a new session is established forCOMMANDER_USERon the CloudBees CD/RO test instanceCOMMANDER_SERVER. - The session is invalidated after completion of all the feature methods in
MySpec.
For more details on writing specifications, refer to the example specifications and Spock.