Chapter 1: Writing a System Test
|
function | description |
---|---|
initTestCase | called once immediately after the test is started. If initTestCase fails, which could happen if you add verification steps in the function, no test will be executed. In normal circumstances, each test will be executed after initTestCase is finished. |
init | called immediately before a test function is executed. If a test function has multiple test data sets (to be discussed later) then init() will also be called multiple times. When init() fails, the test function will be skipped. |
cleanup | called immediately after a test function has finished executing. cleanup() is guaranteed to be called, even if the test function has failed, i.e. you still get a chance to cleanup the environment after a failure. |
cleanupTestCase | called once after the last test function has been executed. |
Let's re-write our testcase a bit, but this time we use the special functions.
testcase = { initTestCase: function() { print( "Init complete test" ); }, cleanupTestCase: function() { print( "Cleanup complete test" ); }, init: function() { print( "Init test function" ); }, cleanup: function() { print( "Cleanup test function" ); }, testFunction1: function() { print( "Hello World" ); }, testFunction2: function() { print( "Testfunction 2" ); } }
When we run qbuild test again we get the following output:
********* Start testing of sys_demo ********* Config: Using QTest library 4.4.2, Qt 4.4.2 QDEBUG : sys_demo::initTestCase() Init complete test PASS : sys_demo::initTestCase() QDEBUG : sys_demo::testFunction1() Init test function QDEBUG : sys_demo::testFunction1() Hello World QDEBUG : sys_demo::testFunction1() Cleanup test function PASS : sys_demo::testFunction1() QDEBUG : sys_demo::testFunction2() Init test function QDEBUG : sys_demo::testFunction2() Testfunction 2 QDEBUG : sys_demo::testFunction2() Cleanup test function PASS : sys_demo::testFunction2() QDEBUG : sys_demo::cleanupTestCase() Cleanup complete test PASS : sys_demo::cleanupTestCase() Totals: 4 passed, 0 failed, 0 skipped ********* Finished testing of sys_demo *********
System tests do not have direct access to the code under test. Instead, the system testrunner connects to Qt Extended, and sends and receives information via a communication protocol. This effectively controls access to the tested system, reducing the impact of tests on results and emulating standard user behaviour.
Suppose we wish to create a simple test which launches an application; we first need to ensure that Qt Extended has finished loading successfully, since we can't be sure of the state of the system we have connected to. This is accomplished by using the waitForQtopiaStart() function in initTestCase():
initTestCase: function() { waitForQtopiaStart(); }
Since initTestCase() is called before any test functions are executed, this will pause test execution until it receives confirmation that Qt Extended has started. Now we're ready to start the application:
testFunction1: function() { startApplication( "Contacts" ); }
The startApplication() method will attempt to start the specified application (in this case, Contacts). If the specified application cannot be started, testFunction will generate a test failure and abort the test.
Once the application has started, we can begin testing. While it is possible to execute as many actions in a test function as desired, the recommendation is to dedicate each test function to a single use case. The test function should then attempt to realistically simulate each step of the use case, and verify that the expected result occurs. For example, assume we need to test creating a new contact; a simple test function could look like this:
creating_a_contact: function() { // Start the application startApplication( "Contacts" ); // Open the options menu and choose "New contact" select( "New contact", optionsMenu() ); // Enter some details in the "Name" and "Emails" fields enter( "Frank Grimes", "Name" ); enter( "frank@example.com", "Emails" ); // Select 'Back' from the softkey menu to commit changes select( "Back", softMenu() ); // We should now be at the contacts list. // Verify that we can select the contact we just created. select( "Frank Grimes" ); // We should now be viewing the contact. // Move to "Details" tab. select( "Details", tabBar() ); // Now verify that the details screen contains // the expected details. var text = getText(); verify( text.contains("Frank Grimes") ); verify( text.contains("frank@example.com") ); }
This test function will start Contacts, navigate through several screens, input data, and verify that the data was successfully saved as a new contact. It is important to note that this test has not explicitly simulated any key or mouse events (although this can be done). This means that the same test can be used as-is on both a keyboard and touchscreen device. This is possible because the implementation of select() and enter() know how to select items and enter data on both keyboard and touchscreen devices.
The next chapter gives more detail on how navigation works.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt qtextended4.4 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com