wiki:DeveloperGuidelines/Testing/EdenTest/WriteTestcase

Version 5 (modified by Arnav Sharma, 11 years ago) ( diff )

--

Writing testcases for EdenTest

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 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 EdenTest.

As EdenTest is built on the principle of 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, write the tests which covers your functionality before writing the code for the functionality. Then, write the code for that functionality so that it passes the tests. The T aspect of F.I.R.S.T.

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 redirects to the homepage of Eden, 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.

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.]
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 Selenium2Library Keyword Documentation and the documentation of keywords implemented under EdenTest in tests/docs.

Advanced Test Design

Please see the article Advanced Test Design.

Note: See TracWiki for help on using the wiki.