Skip to main content

Variables w/ Includes

So far, in this tutorial we have

  • manually invoked a GitHub workflow to publish pre-canned results
  • implemented and executed new test specs from scratch
  • learned how to generate and manage GitHub issues with failing tests
  • formally defined a test session consisting of a set of specs for testing a build
  • leveraged Exploratory Testing for non-scripted verification

This section of the tutorial will focus on implementing specs using Variables and Includes.

But first, let's start with demonstrating how you can use your desktop to write and review test specs using Jekyll.

tip

See Desktop Preview for developing and reviewing Test Specs on your desktop leveraging Jekyll.

Using the Tutorial Repo, execute the following command on your console:

cd specs
bundle install

Run Jekyll to confirm setup: http://127.0.0.1:4000/

bundle exec jekyll serve 

You should see the following page displayed:

Desktop Jekyll View

For details on setting up Jekyll, refer to the Desktop Preview section of the help.

Note to stop Jekyll press ctrl-c on the console.

tip

For an example of using variables and includes, take a look at this Vars and Include test spec.

Variables

Custom variables are defined in the front matter block on a spec.

---
testspace:
title: My New Spec
var1: Hey There
var2: Another var
---

The defined variables can be referenced throughout the spec with the following syntax:

{{ spec.VAR }}

Go ahead and create a new spec, using a similar header as above. Reference the variables throughout the spec. Use Jekyll to review the spec locally before committing.

Includes

Includes enable reusing already defined instructions and steps. An include can also reference variables and additionally can be passed parameters.

All include files are required to be stored under the configured specs folder within a named subfolder called _includes.

Use the following syntax to include a file:

{% include myinc.md %}

To pass parameters provide a variable name and an associated string:

{% include myinc.md myvar="mystring" %}

The include is required to use {{ include.VAR }} when referencing a parameter.

Go ahead and add your own include file to the repo. Reference the file within the newly created spec from the step before.

Confirm the the spec using Jekyll on your desktop.

Once confirmed:

  • Commit and push your changes to the repo
  • Reconfirm the new spec on Testspace

Recap

Testspace supports the use of variables, includes, and parameters when implementing test specs.

  • Allows specs to parameterized
  • Allows re-using instructions and steps within other specs