wiki:DeveloperGuidelines/Testing/EdenTest/WriteTestcase

Version 8 (modified by Arnav Sharma, 7 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 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 #imports library 
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 #opens the browser to the argument url    
    Input Text  auth_user_email  admin@example.com #puts arg2 in textbox(arg1)
    Input Text  auth_user_password  testing
    Click Button  xpath=//input[@class='btn' and @value='Login'] #Clicks the submit button
    Page Should Contain  Logged in #Checks if the text 'Logged in' is there or not

Note: Please make sure that the various arguments are separated by two spaces.

pybot tests/implementation/testsuites/login_functionality.txt. 
  • Open report.html to see the outcome.

Understanding the testcase


  • The testcase is in a separate file and has two sections - *** Setttings *** and *** Test Cases *** itself.
  • 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 and that is one of aims as well, that even someone without the technical know-how can read and write tests.

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.