0

Let me start by stating I am very wet behind the ear with gherkins and cucumber.

I've put together a PoC for my company of an integration a Jenkins projects that will build and execute tests when there is a check in a Git repository. When the tests have completed Jenkins will then update the test managed in Xray for Jira.

The tests are cucumber written using gherkins. I have in vain attempted to cause a single test to produce a failure just to be able to add that to the demo I am going to be giving to upper management.

Here is the contents of my file HelloWorld.feature:

Feature: First Hello World

  @firsth @hello @XT-93
  Scenario Outline: First Hello World
    Given I have "<task>" task
    And Step from "<scenario>" in "<file>" feature file
    When I attempt to solve it
    Then I surely succeed
    Examples:
      | task  | scenario     | file          |
      | first | First Hello | First Feature |

Currently all the tests I have pass. I have attempted to modify that test so that it would fail but thus far have only been able to get it to show in Xray as EXECUTING or TO DO.

I have searched to see if it was possible to create a test that would always result in a test failure but have not been able to find anything.

I know do not know gherkins, I'm only using what was given to me to work with, so please forgive my question.

Thank you for any guidance anyone might be able to provide.

Bob Ford
  • 3
  • 2

1 Answers1

1

Cucumber assumes a step passes if no exception is thrown. Causing a test to fail is easy. Just throw an exception in the step definition.

Most unit testing frameworks give you an explicit way to fail a test. You haven't mentioned the tech stack in use, but MS Test for .NET gives you Assert.Fail("reason for failure goes here.");

Or simply throw an explicit exception: throw new Exception("fail test on purpose");

As long as the step throws an exception the entire scenario should fail.

Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92