Robot framework: Differences between suite setup and test setup?

Viewed 11982

I'm new to robot framework. Could any one explain to me the differences between suite setup and test setup? When to use? Examples...

Thank you in advance.

3 Answers

The easiest way to specify a setup or a teardown for test cases in a test case file is using the :setting:Test Setup and :setting:Test Teardown settings in the Setting table. Individual test cases can also have their own setup or teardown. They are defined with the :setting:[Setup] or :setting:[Teardown] settings in the test case table and they override possible :setting:Test Setup and :setting:Test Teardown settings. Having no keyword after a :setting:[Setup] or :setting:[Teardown] setting means having no setup or teardown. It is also possible to use value NONE to indicate that a test has no setup/teardown.

* Settings *

Test Setup Open Application App A

Test Teardown Close Application

* Test Cases *

Default values

[Documentation]    Setup and teardown from setting table

Do Something

Overridden setup

[Documentation]    Own setup, teardown from setting table

[Setup]    Open Application    App B

Do Something

No teardown

[Documentation]    Default setup, no teardown at all

Do Something

[Teardown]

No teardown 2

[Documentation]    Setup and teardown can be disabled also with special value NONE

Do Something

[Teardown]    NONE

Using variables

[Documentation]    Setup and teardown specified using variables

[Setup]    ${SETUP}

Do Something

[Teardown]    ${TEARDOWN}

Taking above example posted by Waman

*** Settings ***
Suite Setup   Setup feature environment
Test Setup    my Test Setup

*** Keyworods ***
Setup feature environment
    <set required environment variables>
    <copy required files and folders>
    <etc, etc .. >

my Test Setup
    <clean up or release previous test resources>
    <reset environment>
    <etc, etc .. >

*** Test Cases ***
First test
    < test steps>

Second test
    [setup]  Testcase specific setup
    < test steps>

Third test
    < test steps>

So here, when you run the whole file (Suite), all the 3 tests will be executed. The order in which they are executed is :

Setup feature environment --> my Test Setup --> First Test --> Testcase specific setup --> Second test --> my Test Setup --> Third test

The [setup] in second test case overrides the [Test Setup]. So 'my Test Setup' is not executed in second test case

Related