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

Typical usage:

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

A Test that Depends on "Passing Test"
    Depends on test  Passing Test
    Log  The rest of the keywords in this test will run as normal.

When you need to declare multiple dependencies, just repeat the keyword:

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

A Test that Depends on Both "Passing Test" and "Another Passing Test"
    Depends on test  Passing Test
    Depends on test  Another Passing Test
    Log  The rest of the keywords in this test will run as normal.

You can also depend on the statuses of entire test suites:

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

Failures

The Depends on ... keywords fail if the dependency is not met, so the test case automatically aborts with a failure unless you use something like Run keyword and expect error.

Error Messages

The error messages are considered part of the interface, so per SemVer the major version number will be bumped if the error message format ever changes).

If a test failed when you expected it to pass,

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

the error message will be:

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

If Some Test was skipped, the error message would be be:

Dependency not met: test case 'Some Test' state is 'SKIP', wanted 'PASS'

If you typo a test, or try to depend on the status of a test before it has been run, there won’t be any status yet,

*** Test cases ***
A Test that Depends on Missing Test Case
    Depends on test  Another Test

so the error message will be:

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

If you accidentally make a test depend on itself,

*** 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'

When depending on test suites, the error messages are the same, but they use the words “test suite” instead of “test case”.

Extras

You’ll probably never need to, but you can depend on a failure or skip of a test or suite instead of success:

*** Test cases ***
Failing Test
    Fail  This test always fails

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

Skipped Test
    Skip  This test always skips

A Test that Depends on "Skipped Test" Getting Skipped
    Depends on test skipped  Skipped Test
    Log  The rest of the keywords in this test will run as normal.

A Test that Depends on an Entire Test Suite Failing
    Depends on suite falure  Another Test Suite Name
    Log  The rest of the keywords in this test will run as normal.

A Test that Depends on an Entire Test Suite Getting Skipped
    Depends on suite skipped  Some Test Suite Name
    Log  The rest of the keywords in this test will run as normal.

For symmetry with the above, the keywords Depends on test success and Depends on suite success are available as synonyms for Depends on test and Depends on suite.

*** 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

robotframework-dependencylibrary-1.0.1.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

robotframework_dependencylibrary-1.0.1-py2.py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 2 Python 3

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