Skip to content

ec-specs example specifications for testing your CloudBees CDRO releases, pipelines and more

License

Notifications You must be signed in to change notification settings

cloudbees/ec-specs-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ec-specs examples

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.

Prerequisites

NOTE: The CloudBees CD/RO server can be running locally, on a remote server, or in a Kubernetes cluster.

Compile tests

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 Unavailable message 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:

  1. Run git pull on the ec-specs-examples repository. This updates the JAR archive path.
  2. Follow the instructions to compile tests again.

This downloads the dependencies again and should resolve the issue.

Run tests

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 localhost with the default password for admin user:
    mvn test
    
  • For the CloudBees CD/RO server running on a remote server, for example test-remote-server, using user credentials test-user/test-user-password:
    mvn -DCOMMANDER_SERVER=test-remote-server -DCOMMANDER_USER=test-user -DCOMMANDER_PASSWORD=test-user-password test
    

Write specification (spec test) classes

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.

Structure of a simple specification class

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"() {
        //...
    }
    
}
  • MySpec contains two feature methods:
    • my dsl works as expected
    • another test
  • Before the feature methods in MySpec run, a new session is established for COMMANDER_USER on the CloudBees CD/RO test instance COMMANDER_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.

Additional resources

About

ec-specs example specifications for testing your CloudBees CDRO releases, pipelines and more

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published