Applications often have a set of business rules; rules that govern how an application should react based on a given set of input or actions. Or as Wikipedia defines it:
A business rule is a rule that defines or constrains some aspect of business and always resolves to either true or false. Full definition
Validate your application’s business rules using data-driven tests
Take a simple set of steps, perhaps even a Snippet of a Test Case, let’s say lines 7 – 10 in the following example:
def main(): startApplication("AddressBookSwing.jar") activateItem(waitForObjectItem(":Address Book_JMenuBar", "File")) activateItem(waitForObjectItem(":File_JMenu", "New...")) activateItem(waitForObjectItem(":Address Book - Unnamed_JMenuBar", "Edit")) activateItem(waitForObjectItem(":Edit_JMenu", "Add...")) type(waitForObject(":Address Book - Add.Forename:_JTextField"), "sam") type(waitForObject(":Address Book - Add.Surname:_JTextField"), "smith") type(waitForObject(":Address Book - Add.Email:_JTextField"), "sam@smith.com") type(waitForObject(":Address Book - Add.Phone:_JTextField"), "123.123.1234") clickButton(waitForObject(":Address Book - Add.OK_JButton"))
Ask yourself (or better yet, your team):
- What are the valid input values in each of these fields?
- What values are not permitted in each of these fields?
- Do the fields have any minimum character requirements?
- Any maximum character requirements?
- What should display in the event any of these requirements are not met? And when should it display?
Given answers to the above set of questions, you can begin compiling a collection of data to validate the business rules.
Business Rules Data Table
field | input | result_details | comments | |
1 | Forename | sam | Expected Result: input accepted without error | |
2 | Forename | s@m | Special characters not permitted in Forename field | Expected Result: Warning message appears immediately |
3 | And | so | on | … |
Modify your Test Case to use the data
Use the Make Code Data Driven wizard to give yourself a jump start.
Then
- Update the text field to use the related variable(s) and
- Add a verification point to validate the expected result
Updated example
def main(): startApplication("AddressBookSwing.jar") activateItem(waitForObjectItem(":Address Book_JMenuBar", "File")) activateItem(waitForObjectItem(":File_JMenu", "New...")) activateItem(waitForObjectItem(":Address Book - Unnamed_JMenuBar", "Edit")) activateItem(waitForObjectItem(":Edit_JMenu", "Add...")) for record in testData.dataset("businessRules.tsv"): field = testData.field(record, "field") input = testData.field(record, "input") result_details = testData.field(record, "result_details") comments = testData.field(record, "comments") textField = waitForObject(":Address Book - Add.%s:_JTextField" % field) textField.setText("") type(waitForObject(textField), input) waitFor("object.exists(':Address Book - Add.%s_Warning:_JLabel' % field)", 20000) test.compare(findObject(":Address Book - Add.%s_Warning:_JLabel" % field).text, result_details, comments)