Revision: 4652
Author: [email protected]
Date: Mon Feb 28 17:24:00 2011
Log: Created wiki page through web user interface.
http://code.google.com/p/robotframework/source/detail?r=4652

Added:
 /wiki/TestStructure.wiki

=======================================
--- /dev/null
+++ /wiki/TestStructure.wiki    Mon Feb 28 17:24:00 2011
@@ -0,0 +1,129 @@
+#summary Where should new keywords and tests go
+
+<wiki:toc max_depth="2" />
+
+= Introduction =
+
+These are high level guidelines on how to structure your tests in terms of where to add keywords and where to add new tests.
+
+= Should my keyword be in this file or library or some shared resource file? =
+
+* If your keyword has complicated logic -> In a library!
+
+<table>
+<tr><th>`invalid_login_should_fail.txt`</th><th>`invalid_login_should_fail.txt`</th></tr>
+<tr><td>
+{{{
+*** Keywords ***
+Get Step Message     [Arguments]    ${step}
+  ${init result}  Run Keyword If  ${step}==0  System Initialization
+  ${step result}  Run Keyword If  ${step}>0   Call System Step  ${step}
+  ${illegal result} Run Keyword If  ${step}<0  Illegal Step
+  ${result} =     Set Variable If  ${step}==0  ${init result}
+                  ...              ${step}>0   ${step result}
+                  ...              ${illegal result}
+  [Return]    ${result}
+}}}
+</td>
+<td>
+{{{
+def get_step_message_python(step):
+     if (step == 0):
+          return system_initialization()
+     if (step > 0):
+          return call_system_step(step)
+     else:
+          return illegal_step()
+}}}
+</td></tr>
+</table>
+
+ * Choosing between test suite file and a shared resource file depends from the situation.
+
+ * If your keyword could be useful to others its best to move it shared resource. Always better to avoid duplicate work. + * Document your keyword. Especially if you take arguments or return values. + * Make sure that you dont do unnessary sleeps. Always use Wait Until Keyword Succeeds if possible. + * Avoid "Set Test Variable", "Set Suite Variable", and "Set Global Variable" in shared keywords.
+
+<table>
+<tr><th>`valid_login.txt`</th><th>`valid_login.txt`</th></tr>
+<tr><td>
+{{{
+*** Test Cases ***
+Withdraw From Account
+  ${status} =   Withdraw From Account    50$
+  Withdraw Should Have Succeeded     ${status}
+
+*** Keywords ***
+Withdraw From Account
+  [arguments]   ${amount}
+  ${status} =   Withdraw From User Account  ${USER}  ${amount}
+  [return]      ${status}
+
+Withdraw Should Have Succeeded
+  [arguments]   ${status}
+  Should Be Equal   ${status}   SUCCESS
+}}}
+</td>
+<td>
+{{{
+*** Test Cases ***
+Withdraw From Account
+  Withdraw From Account    50$
+  Withdraw Should Have Succeeded
+
+*** Keywords ***
+Withdraw From Account
+  [arguments]   ${amount}
+  ${status} =   Withdraw From User Account  ${USER}  ${amount}
+  Set Test Variable   ${status}
+
+Withdraw Should Have Succeeded
+  Should Be Equal   ${status}   SUCCESS
+}}}
+</td></tr>
+</table>
+
+
+
+= In which suite should my test be? =
+ - new case into a folder with 10 suite files. Which one to choose? + - Should One file be for one team? One Feature? One Userstory? +- Usually best structure comes from tests with same setup/teardown being in the same file.
+          - So look at setups/teardowns, if same = same suite!
+
+ - tags can be used for tagging features/teams/whatever you otherwise would use filenames for
+
+          - One suite file for 1-20 test cases. Preferably no more than 10.
+
+If you have tests with very heavy setups and teardowns, they can be made depend on each other
+     - generally should be avoided
+     - if done, they should be in the same file
+     - Never have long chains of dependent tests (max 4-5).
+ - Consider verifying the status of the previous test using ${PREV TEST STATUS} and ${PREV TEST NAME} variables.
+
+Example of tests depending from each other:
+
+Before:
+Heavy test 1
+   Setup system
+   Do a long heavy workflow
+   Check system status is OK
+
+Second heavy test
+   Setup system
+   Do a long heavy workflow
+   Second heavy workflow
+   Check system status is OK
+
+After:
+Heavy test 1
+   Setup system
+   Do a long heavy workflow
+   Check system status is OK
+
+Second heavy test
+   Should Be Equal  ${PREV TEST STATUS}   PASS
+   Should Be Equal  ${PREV TEST NAME}      Heavy Test 1
+   Second heavy workflow
+   Check system status is OK

Reply via email to