Chapter 4: Putting It All Together
Using the simple building blocks of textual input and output and navigation functions, with the data driven testing approach, a full testcase can be written for creating a new contact. Note that the functions for creating and verifying a contact have been moved out into helper functions; this allows them to be reused for subsequent tests. This is very useful for cases where, for instance, one test's precondition might be that a contact has been successfully created.
testcase = {
initTestCase: function() {
startApplication( "Contacts" );
},
creating_a_contact: function(name, emails, company, jobTitle, businessPhone) {
create_contact(name, emails, company, jobTitle, businessPhone);
verify_contact(name, emails, company, jobTitle, businessPhone);
},
creating_a_contact_data: {
simple: [ "Billy Jones", "billy@example.com", "Hotdog Inc.", "Hotdog Engineer", "12345" ],
letters_in_phone: [ "Joan Example", "joan@example.com", "Example Inc.", "Exemplary Engineer", "555 EXA" ],
three_names: [ "Jon John Johnson", "jjj@example.com", "Sillynames Inc.", "Dog Walker", "12345" ],
no_job: [ "William Doe", "bill@example.net", undefined, undefined, undefined ]
}
}
function create_contact(name, emails, company, jobTitle, businessPhone) {
waitForTitle( "Contacts" );
select( "New contact", optionsMenu() );
select( "Contact", tabBar() );
enter( name, "Name" );
enter( emails, "Emails" );
select( "Business", tabBar() );
enter( company, "Company" );
enter( jobTitle, "Title" );
enter( businessPhone, "Phone" );
select( "Back", softMenu() );
}
function verify_contact(name, emails, company, jobTitle, businessPhone) {
waitForTitle( "Contacts" );
select( name );
select( "Details", tabBar() );
var details = getText();
if (name != undefined) verify( details.contains(name) );
if (emails != undefined) verify( details.contains(emails) );
if (company != undefined) verify( details.contains(company) );
if (jobTitle != undefined) verify( details.contains(jobTitle) );
if (businessPhone != undefined) verify( details.contains(businessPhone) );
}
The above test has been written to be reasonably permissive; it will succeed as long as the text shown by the contacts application contains all of the information for the created contact, and it does not test things such as the formatting of the given text, and does not test every single field. However, this test is well insulated against minor changes to the tested application GUI.
QtUiTest allows the tester to decide how strict a test should be. If pixel-perfect accuracy is required for output, a test can be written to test every screen with verifyImage(). In contrast, a high-level text-based approach as shown above can result in effective tests which remain correct even when significant UI changes occur.
There are many other methods available for use; for further information, refer to the QSystemTest documentation.
[Previous: Chapter 3]
[Contents]