= Writing testcases for !EdenTest = [[TOC]] == The F.I.R.S.T principle of Test Driven Development == * '''Fast''': run (subset of) tests quickly (since you'll be running them all the time) * '''Independent''': no tests depend on others, so can run any subset in any order * '''Repeatable''': run N times, get same result (to help isolate bugs and enable automation) * '''Self-checking''': test can automatically detect if passed (no human checking of output) * '''Timely''': written before writing the code !EdenTest has been written using these principles. Whenever using EdenTest to create a new testcase, it is imperative to make sure that '''F.I.R.S.T''' mantra is followed. == How to write good testcases? == Before beginning to write a testcase, please go through the article [https://code.google.com/p/robotframework/wiki/HowToWriteGoodTestCases How to write good testcases for Robot Framework?]. It is a short and descriptive article that will help you a great deal to write precise and useful testcases. == Writing a testcase for !EdenTest == Before writing your first testcase, please make sure that you have !EdenTest set up, you understand the directory structure and the know-how of how to run !EdenTest and see its results. If not, go through [http://eden.sahanafoundation.org/wiki/DeveloperGuidelines/EdenTest EdenTest]. As !EdenTest is built to make it easy to do '''ATDD''' which is a practice in which the acceptance criteria is decided, with examples, and then distilled into a set of concrete acceptance tests before development begins. To say it simply, ATDD is like: 1. Define (or refactor) acceptance test(s) from user stories 2. Automate the acceptance test 3. Run the acceptance test 4. If fail: refactor code, then repeat 3. If pass: development stops, back to 1. === What we have to do? === Let us assume you have to implement a simple login form. The user story is as follows: It asks for the email and password. If the login is successful, it shows the message 'Logged In', if unsuccessful it shows an error. We will write the testcase to check if successful login works. === Writing the testcase === Follow these steps: * Create a file named login_functionality.txt inside the folder '''/tests/implementation/testsuites'''. * Write the testcase below in it {{{ *** Settings *** Library Selenium2Library Variables ../../execution/config.py #contains the local settings Test Teardown Close Browser #close the browser after running the test *** Test Cases *** Login with valid email and valid passwd should be successful #name of the testcase. Open Browser http://${SERVER}/eden/default/user/login Input Text auth_user_email admin@example.com Input Text auth_user_password testing Click Button xpath=//input[@class='btn' and @value='Login'] Page Should Contain Logged in }}} Note: Please make sure that the various arguments are separated by two spaces at least. [[BR]] * Run the testsuite login_functionality.txt. ([http://eden.sahanafoundation.org/wiki/DeveloperGuidelines/EdenTest#UsingEdenTest Using EdenTest]) {{{ pybot tests/implementation/testsuites/login_functionality.txt. }}} * Open '''report.html''' to see the outcome. === Understanding the testcase === [Ignore the `*** Settings ***` section for the time being.] [[BR]] As you can see, the name of the testcase is very descriptive and describes the objective. '''Open Browser''', '''Input Text''', '''Click Button''' and '''Page Should Contain''' are all keywords (functions) implemented in Selenium2Library. The beauty of writing tests this way is that they are easy to read and understand, thus eliminating the need to explain them. If you have understood how the above above testcase is written, try writing the testcase '''Login with invalid email and valid passwd should fail'''. It should be fairly simple. To understand the selenium keywords visit [http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library.html Selenium2Library Keyword Documentation] and the documentation of keywords implemented under !EdenTest in '''tests/docs'''. == Advanced Test Design == Please see the article [http://eden.sahanafoundation.org/wiki/DeveloperGuidelines/EdenTest/WriteTestcase/Advanced Advanced Test Design].