Should I use Force Tags or Default Tags

Viewed 1069

I want to make use of Tags to note down the defect ID in test case. So that I can run specific test case which defect occurred easily.

From user guide, example, there is Force Tags and Default Tags at settings. For my case, which one should I use? :

*** Settings ***
Force Tags      req-42
Default Tags    owner-john    smoke

*** Variables ***
${HOST}         10.0.1.42

*** Test Cases ***
No own tags
    [Documentation]    This test has tags owner-john, smoke and req-42.
    No Operation

With own tags
    [Documentation]    This test has tags not_ready, owner-mrx and req-42.
    [Tags]    owner-mrx    not_ready
    No Operation

Own tags with variables
    [Documentation]    This test has tags host-10.0.1.42 and req-42.
    [Tags]    host-${HOST}
    No Operation

Empty own tags
    [Documentation]    This test has only tag req-42.
    [Tags]
    No Operation

Set Tags and Remove Tags Keywords
    [Documentation]    This test has tags mytag and owner-john.
    Set Tags    mytag
    Remove Tags    smoke    req-*

My test cases is written in one file and setup as test suite, the defect appear at one of step for both cases, is this the correct setup?:

*** Settings ***
Resource            ../Resources/res.robot
Suite Setup         Suite Setup Suite
Test Setup          Test Setup
Suite Teardown      Test Teardown
Default Tags        Defect1


*** Test Cases ***
TC001-001-01
    [Tags]   Defect1
    Go To Page  1
    Go Back

TC001-001-02
    [Tags]   Defect1
    Go To Page  2
    Go Back
1 Answers

If you want both your tests to get the tag Defect1 then you can use either Force Tags in the Settings or [Tags] in the tests themselves.

Default Tags is not appropriate in that case because you would take the risk that some tests don't get the Defect1 tag if some other tag is defined on the test.

So I would say the 2 possibilities are:

  1. Use of [Tags] (handy because you see directly when looking at a test that it has the tag)
*** Settings ***
Resource            ../Resources/res.robot
Suite Setup         Suite Setup Suite
Test Setup          Test Setup
Suite Teardown      Test Teardown


*** Test Cases ***
TC001-001-01
    [Tags]   Defect1
    Go To Page  1
    Go Back

TC001-001-02
    [Tags]   Defect1
    Go To Page  2
    Go Back
  1. Use of [Force Tags] (handy because you don't have to repeat the tag on each test)
*** Settings ***
Resource            ../Resources/res.robot
Suite Setup         Suite Setup Suite
Test Setup          Test Setup
Suite Teardown      Test Teardown
Force Tags          Defect1


*** Test Cases ***
TC001-001-01
    Go To Page  1
    Go Back

TC001-001-02
    Go To Page  2
    Go Back
Related