robotframework / HowToWriteGoodTestCases

General guidelines for writing good test cases using Robot Framework
406 stars 191 forks source link

State scoped variables more precisely #8

Closed KUGA2 closed 4 years ago

KUGA2 commented 4 years ago

Before it was kind of unclear, if you should use lower or upper case in test cases. I interpreted this: Yes, they should be lower case, unless they are used (but not passed!) in keywords. This is now more clear (to me).

Tattoo commented 4 years ago

This is unfortunately incorrect. Variables are not global if they are defined for example in a test case:

*** Test cases ***
My test case
     ${my local variable}=    Set variable    foo

My second test case
    Log    ${my local variable}

or in a keyword:

*** Test cases ***
My test case
    My kw
    My second kw

*** Keywords ***
My kw
     ${my local variable}=    Set variable    foo

My second kw
    Log    ${my local variable}

Given how common returning values from keywords is, most variables probably are local, rather than test-, suite- or globally scoped

KUGA2 commented 4 years ago

So, all variables are local (used as a synonym for scoped), but those set in the ***Variable*** section or those set with Set Test/Suite/Global Variable keyword?

Tattoo commented 4 years ago

So, all variables are local (used as a synonym for scoped), but those set in the ***Variable*** section or those set with Set Test/Suite/Global Variable keyword?

I don't know if this comment is relevant to your PR, but for the sake of completeness:

You can also have variables coming from command line, from variable files, and from libraries (this is technicality, doing this in library would be really esoteric in my opinion) which are also not local.

KUGA2 commented 4 years ago

Thanks. I will cancel this pull request.