Tuesday, March 23, 2010

Automated Testing: How to write automatable test cases?

Test cases are used in software testing extensively. Plainly speaking, a test case consists of one or more steps. The test case may have expected results given for one or more steps. Test cases commonly have other information such as an ID, a description, some pre-conditions and test data.
If you want to automate test cases without re-working them or making a lot of assumptions, you should ensure that the test cases at hand are specific. Here are some guidelines below. If you have been handed test cases authored by someone else, you can use these guidelines to determine if you need to modify these test cases before you automate them. If you are going to write test cases that would be automated later, you should follow these guidelines to make your test cases automation-friendly. Some of these guidelines are also applicable to writing test cases that are not marked for automation. I have used examples from Microsoft Word for your convenience.
.
GuidelinesFor example, instead ofIt should mention
1. The test case should specify each pre-condition.Not giving any pre-condition Close MS Word if it is already open.
2. The test case should not leave an action to the judgment of the automation tester.Just saying, "Open MS Word."Open MS Word from Start > Programs > Microsoft Office > Microsoft Office Word nnnn.
3. The test case should specify the test data in each applicable step. Saying, "Open any existing MS Word file."Open an existing MS Word file (C:\Abc.doc).
4. The test case should have all the required steps.Mentioning "It should be possible to save the changes made by the user." as an expected resultTwo separate steps, 1) for saving changes to a new file and 2) for saving changes to an existing file.
5. The test case should not hide some details.Mentioning "Type a word with incorrect spelling. The word should be underlined with a squiggly line."Type a word with incorrect spelling. The word should be underlined with a red squiggly line.
6. A step should not force one choice. Saying "Enter a word using the keyboard or Insert > Symbol feature".Two steps, 1) entering a word using the keyboard and 2) entering a word using the Insert > Symbol feature.
7. The test case should specify (and not imply) any clean up steps.Missing any steps to clean upThe steps to remove the added word from the Dictionary or reset MS Word to its original setting (if the test case requires a word to be added to the MS Word Dictionary).
8. The test case should describe the expected results as completely as required.Saying "Close MS Word without saving your changes. There should be a dialog box asking you to save your changes."Close MS Word without saving your changes. There should be a dialog box titled "Microsoft Office Word" with the text, "Do you want to save the changes to ...? and three buttons labeled Yes, No and Cancel."
The above guidelines should ease your struggle when you examine the test cases to automate them. Have you found any other problem with the test cases when you sought to automate them? Comment your problem.