Skip to main content

Declare dependencies between Robot Framework tests

Project description

Declare dependencies between tests. Make tests automatically fail based on the results of other test cases or test suites.

Although I strongly recommend that people write tests to be independent, sometimes, dependencies between tests are the simplest and easiest model to implement, and having tests fail-fast if one or more previous test cases didn’t get the expected result can be beneficial.

Versioning

This library’s version numbers follow the SemVer 2.0.0 specification.

Installation

pip install robotframework-dependencylibrary

Usage

First, include the library in your tests:

*** Settings ***
Library  DependencyLibrary

Let’s say you have a passing and failing test:

*** Test cases ***
Passing Test
    No operation

Failing Test
    Fail  This test is intentionally hardcoded to fail

A basic test that depends on the passing test looks like this:

*** Test cases ***
This Test Depends on "Passing Test" Passing
    Depends on test  Passing Test
    Log  The rest of the keywords in this test will run as normal.

Of course, you can depend on a test failure instead:

*** Test cases ***
This Test Depends on "Failing Test" Failing
    Depends on test failure  Failing Test
    Log  The rest of the keywords in this test will run as normal.

You can also depend on the status of a test suite:

*** Test cases ***
This Test Depends on an Entire Test Suite Passing
    Depends on suite  My Test Suite Name
    Log  The rest of the keywords in this test will run as normal.

Failures

Since the Depends on ... keywords fail when the dependency is not met, it supports all the usual logic you’d expect from Robot Framework:

The test case automatically aborts with a failure when the Depends on ... keyword fails as you’d expect, unless you capture the status and error message using something like Run keyword and expect error.

Error Messages

The error messages are documented (and are considered part of the interface, so you can rely on SemVer semantics: the major version number will be bumped if the logic for error messages ever changes):

If a test failed when you expected it to pass, you’ll get a helpful error:

*** Test cases ***
This Test Depends on "Failing Test" Passing
    Depends on test  Failing Test
    Log  The rest of the keywords (including this log) will NOT run!

The error message will be:

Dependency not met: test case 'Failing Test' state is 'FAIL', wanted 'PASS'

Same with expecting a passing test to fail:

*** Test cases ***
This Test Depends on "Passing Test" Failing
    Depends on test failure  Passing Test
    Log  The rest of the keywords (including this log) will NOT run!

The error message will be:

Dependency not met: test case 'Passing Test' state is 'PASS', wanted 'FAIL'

If you typo a test, or try to depend on the status of the test before it’s been run, for example:

*** Test cases ***
Depends on Non-Existant Test Case
    Depends on test  Misnamed Test

The error message will be:

Dependency not met: test case 'Misnamed Test' not found, wanted 'PASS'

If you accidentally make a test depend on itself, it will give a similar error message that more precisely identifies the error:

*** Test cases ***
Depends on self
    Depends on test  Depends on self

The error message will be:

Dependency not met: test case 'Depends on self' mid-execution, wanted 'PASS'

All test suite error messages are the same, except that they use the words “test suite” instead of “test case”.

Extras

For symmetry with Depends on test failure, the keyword Depends on test success is available as a synonym for Depends on test:

*** Test cases ***
This Test Depends on "Passing Test" Passing (using alternate keyword)
    Depends on test success  Passing Test
    Log  The rest of the keywords in this test will run as normal.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page