Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this tutorial, we will create some tests in Cucumber for Perl.

In this case, the The test (specification) is initially created in JIRA Jira as a Cucumber Test and afterwards, it is exported using the UI or the REST API.

Requirements

...

We will use the code from the  Github repository "test-bdd-cucumber-perl" , with some slight changes.

 


So the The first step is to create two Cucumber Tests, one "Scenario" and one "Scenario Outline", in JIRAJira. The specification would be similar to the calculator example provided in the Github repository.

After we create creating the Tests in JIRA, and associate it Jira and associating them with requirements, etc., you can export the specification specifications of the test to a Cucumber .feature file (e.g. by via the REST API or by the UI action "Export to Cucumber" UI action from within the Test Execution issue).

The created file will be similar to the original one , but will contain the references to the Test issue key and the covered requirement issue key.

 


Based on With the provided code below, weyou'll create a simple feature file as follows. Note that we have introduced a bug on purpose in the Scenario Outline specification on purpose (i.e., "6/3=3").

Code Block
titlefeatures/basic_functions.feature
@CALC-xx
Feature: Basic Calculator Functions
  In order to check I've written the Calculator class correctly
  As a developer I want to check some basic operations
  So that I can have confidence in my Calculator class.

  @CALC-885 @CALC-886
  Scenario: First Key Press on the Display
    Given a new Calculator object
    And having pressed 1
    Then the display should show 1

  @CALC-886 @CALC-887
  Scenario Outline: Basic arithmetic
    Given a new Calculator object
    And having keyed <first>
    And having keyed <operator>
    And having keyed <second>
    And having pressed =
    Then the display should show <result>
    Examples:
      | first | operator | second | result |
      | 5.0   | +        | 5.0    | 10     |
      | 6     | /        | 3      | 3      |
      | 10    | *        | 7.550  | 75.5   |
      | 3     | -        | 10     | -7     |

...


Please check if the Scenario Outline is specified using the "Scenario Outline" keywords.

...

Code Block
languageperl
titlelib/Calculator.pm
collapsetrue
package    # hide from PAUSE indexer
  Calculator;
use strict;
use warnings;
use Moose;
has 'left'     => ( is => 'rw', isa => 'Num', default => 0 );
has 'right'    => ( is => 'rw', isa => 'Str', default => '' );
has 'operator' => ( is => 'rw', isa => 'Str', default => '+' );
has 'display' => ( is => 'rw', isa => 'Str', default => '0' );
has 'equals'  => ( is => 'rw', isa => 'Str', default => '' );
sub key_in {
    my ( $self, $seq ) = @_;
    my @possible = grep { /\S/ } split( //, $seq );
    $self->press($_) for @possible;
}
sub press {
    my ( $self, $key ) = @_;
    # Numbers
    $self->digit($1) if $key =~ m/^([\d\.])$/;
    # Operators
    $self->key_operator($1) if $key =~ m/^([\+\-\/\*])$/;
    # Equals
    $self->equalsign if $key eq '=';
    # Clear
    $self->clear if $key eq 'C';
}
sub clear {
    my $self = shift;
    $self->left(0);
    $self->right('');
    $self->operator('+');
    $self->display('0');
    $self->equals('');
}
sub equalsign {
    my $self = shift;
    $self->key_operator('+');
    my $result = $self->left;
    $self->clear();
    $self->equals($result);
    $self->display($result);
}
sub digit {
    my ( $self, $digit ) = @_;
    # Deal with decimal weirdness
    if ( $digit eq '.' ) {
        return if $self->right =~ m/\./;
        $digit = '0.' unless length( $self->right );
    }
    $self->right( $self->right . $digit );
    $self->display( $self->right );
}
sub key_operator {
    my ( $self, $operator ) = @_;
    my $cmd =
        $self->left
      . $self->operator
      . (
        length( $self->right )
        ? $self->right
        : ( length( $self->equals ) ? $self->equals : '0' )
      );
    $self->right('');
    $self->equals('');
    $self->left( ( eval $cmd ) + 0 );
    $self->display( $self->left );
    $self->operator($operator);
}
1;

 

 



After running the tests (see bellow) and generating the Cucumber JSON  report (e.g., data.json), it can be imported to Xray (either by via the REST API or through "the Import Execution Results" action within the Test Execution).

No Format
pherkin -I lib -o JSON features/basic_functions.feature > data.json

...


 


The execution screen details will provide information of on the test run result. 


Info

The Cucumber Scenarios Example/Result details (i.e., Hooks, Backgrounds and Steps) , are only available for executions made with executions done in Xray v2.2.0 and above.

...


For a Cucumber Scenario Test...:


For a Cucumber Scenario Outline Test...:

 


Info

The icon represents the evidences ("embeddings") for each (HooksHook, Backgrounds Background and Steps) Step, but are but is only available for executions made with executions done in Xray v2.3.0 and above.

Info
titleLearn more

Please see Testing with Cucumber for a high-level an overview on how to use Cucumber Tests with Xray.

 


References

...