Robot framework: Differences between suite setup and test setup?

10,640

Solution 1

In the simplest terms possible, a suite setup runs exactly once at the start of a suite. A test setup runs at the start of a test case.

If you define a test setup in the settings section of the suite, it will run at the start of each test in the suite (ie: if you have 5 tests, it will run five times). If you define it in a specific test, it will only run for that test where it is defined.

A suite setup is a good place to do some initialization, such as starting a server, opening a browser, making a database connection, etc.

A test setup is a good place to do some work unique to the test that isn't actually part of the verification. For example, you might use the test setup to log in and navigate to the page being tested.

Solution 2

Test, is a set of operations performed to verify a feature.

Suite, Set of tests defined in same test file, testing the same feature.

Testing a feature means, you might have certain preconditions which may involve setting up environment for testing the feature. So these preconditions could of 2 types, one which can be performed once for entire Suite (all tests), others have to be performed before every test.

Suite Setup, as name implies it is a function (Set of operations) which needs to be performed before running a Suite.

Test Setup, as name implies it is a function (Set of operations) which needs to be performed before every test.

E.g.

*** 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
    < 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 --> my Test Setup --> Second test --> my Test Setup --> Third test

Hope it helps!

Share:
10,640
hungndv
Author by

hungndv

Learning something.

Updated on June 05, 2022

Comments

  • hungndv
    hungndv over 1 year

    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.

  • Waman
    Waman over 6 years
    ahh...Thank you!