• Documentation
  • Tutorials
  • Case studies
  • White papers
  • Product

What's on this Page

  • Sample output
  • Maven dependency
  • Inline plan definitions
  • Selective inclusion of plans, and parameterization
  • step
  • Resources
  • Tutorials
  • JUnit Plan Runner
Categories: TUTORIALS JAVA
This article references one of our previous releases, click here to go to our latest version instead.

JUnit Plan Runner

Starting with version 3.14, step includes a JUnit runner that can be used to seamlessly integrate step plans into JUnit tests.

The documentation of JUnit runner is still under work. It will be completed and supplemented by tutorials and examples soon.

Sample output

Here is an example of what the output of using this feature may look like.

TestKeyword.png

The sections below refer to the structure and files shown in this screenshot. Note that the code examples are intentionally as short and specific as possible, as they are only meant to showcase the syntax and usage.

Maven dependency

<dependency>
    <groupId>ch.exense.step</groupId>
    <artifactId>step-junit</artifactId>
    <version>3.14.0</version>
</dependency>

Inline plan definitions

Here is a simple example which uses the step JUnit runner to run a plan defined directly inside the Test file:

package com.example.step.junit.ex1;

import org.junit.runner.RunWith;
import step.junit.runner.Step;
import step.junit.runners.annotations.Plan;

@RunWith(Step.class) // (1)
public class ExampleTest1 {

    @Plan("Sequence\nEcho \"OK\"\nEnd") // (2)
    public void inlinePlan() {
    }
}

Notice how (1) we are using the @RunWith(Step.class) annotation on the class to define the JUnit runner used for executing the entire Test class, and (2) how the actual plan to be executed is declared in the @Plan annotation of the test method.

Selective inclusion of plans, and parameterization

While inlining plan definitions as shown above is a quick and easy way to run plans as JUnit test cases, it is really only suitable for very short definitions.

Therefore, the step JUnit runner features a mechanism to automatically create test cases when the following conditions are met:

  1. The plan is defined in the @Plans annotations
  2. The plan definitions are located in the resources subdirectory matching the package of the JUnit test.

The test class below shows how to include specific (external) plans, and how to define execution parameters:

package com.example.step.junit.ex2;

import org.junit.runner.RunWith;
import step.junit.runner.Step;
import step.junit.runners.annotations.ExecutionParameters;
import step.junit.runners.annotations.Plans;

@RunWith(Step.class)
@Plans({"keyword_and_params.plan"})
@ExecutionParameters({"INPUT_PARAMETER", "Example"})
public class ExampleTest2 {
}

… and this is the content of the keyword_and_params.plan:

Sequence
Echo "${INPUT_PARAMETER} exists"
CustomKeyword
End

This plan will only execute correctly if:

  1. the parameter INPUT_PARAMETER is defined (using the @ExecutionParameters annotation)
  2. the CustomKeyword keyword is found in the same package as the plan and Test class.

For completeness, here is the trivial implementation of the keyword:

package com.example.step.junit.ex2;

import step.handlers.javahandler.AbstractKeyword;
import step.handlers.javahandler.Keyword;

public class Keywords extends AbstractKeyword {

    @Keyword
    public void CustomKeyword() {
        System.out.println("CustomKeyword called.");
    }
}
  • Getting Started
  • Whats new?
  • Admin guide
  • User guide
  • Developer guide
  • Plugins
  • Resources
    • Tutorials
      • Adding and Configuring New Agents
      • Appium Keyword
      • AutoIt Keyword
      • Basic Keyword Development
      • Browser-based automation with step and Selenium
      • Designing functional tests
      • How to monitor services availability and performance
      • JUnit Plan Runner
      • Load testing with Cypress
      • Load testing with Selenium
      • Microsoft Office automation
      • Setting up system monitoring with a step agent
      • Using step with Grafana
    • Case Studies
    • White papers
    • Blog
    • Libraries
Step Logo
    • Documentation
    • Tutorials
    • Case studies
    • White papers
    • Product
    • Getting Started
    • Whats new?
    • Admin guide
    • User guide
    • Developer guide
    • Plugins
    • Resources
      • Tutorials
        • Adding and Configuring New Agents
        • Appium Keyword
        • AutoIt Keyword
        • Basic Keyword Development
        • Browser-based automation with step and Selenium
        • Designing functional tests
        • How to monitor services availability and performance
        • JUnit Plan Runner
        • Load testing with Cypress
        • Load testing with Selenium
        • Microsoft Office automation
        • Setting up system monitoring with a step agent
        • Using step with Grafana
      • Case Studies
      • White papers
      • Blog
      • Libraries