Skip to content

Running your test code with PackageBuilder

rolivieri edited this page Nov 15, 2016 · 11 revisions

If you need specific packages installed or services running, there is a way to get that accomplished with PackageBuilder. You can configure it so that it will automatically run your custom scripts before and after your tests execute. To do so, create a CI test repository that has the following format:

{Project Name}
   - common
   - linux
   - osx

{Project Name} is the name of your repository that you will be using the test CI test repository with. For example, if your project repository was named "MyProject", then the directory structure layout in the CI test repository will be the following:

MyProject
   - common
   - linux
   - osx

An example of a CI test repository can be viewed at the following URL: https://github.com/IBM-Swift/Kitura-CI

In the Kitura-CI repository, you will find folders for two projects, Kitura-Session-Redis and Kitura-redis. These contain the scripts needed to update the system so that their test cases run. Under the common, linux, and osx folders you can have the following files:

before_tests.sh
after_tests.sh

Depending on your needs, you may need scripts for each one of those folders.

The platform dependent folders (i.e. linux, osx) have scripts that are specific to the corresponding operating system. The common folder has scripts that are common to both platforms. For instance, look at https://github.com/IBM-Swift/Kitura-CI/blob/master/Kitura-redis/linux/before_tests.sh and https://github.com/IBM-Swift/Kitura-CI/blob/master/Kitura-Session-Redis/linux/before_tests.sh. These two scripts are responsible for installing redis. You can then take similar steps to install software components needed for your tests.

If a particular script is not needed, then there is no need to include it in the repository containing the test setup scripts.

Once you have created and configures your CI test repository, you should update your .travis.yml file so that it clones your CI test repository. As a reference, take a look at the following file: https://github.com/IBM-Swift/Kitura-redis/blob/master/.travis.yml. You should see the following code in the .travis.yml file:

before_install:
  - git clone https://github.com/IBM-Swift/Kitura-CI.git
  - git submodule update --init --remote --merge --recursive

By taking the above lines and replacing Kitura-CI with your CI test repository, you will then clone the corresponding CI test repository into your repository during the Travis CI build.

During the following Travis CI build step, PackageBuilder will be invoked to compile and test your project. If your CI test repository was cloned (as documented above), then the test scripts will get invoked and the test cases will be executed:

script:
  - ./Package-Builder/build-package.sh $TRAVIS_BUILD_DIR
Clone this wiki locally