Structuring Tests

Learn how to structure your tests with tuneup

Structuring Tests

One of the big reasons to use tuneup is to give some structure to your UIAutomation tests. Out of the box, UIAutomation doesn’t provide a real first-class way of grouping test code together, so tuneup provides the test function.

The 'test' Function

The test function takes two arguments: a short description of your test and a JavaScript function that accepts two parameters. The description is used by UIAutomation to provide feedback about which test executed. Tuneup passes this string along in such a way that the output from Instruments will be grouped by this string within the trace document generated by Instruments.

The function takes two parameters, typically named app and target. The first is a reference to the UIAApplication instance variable for your application, the second is a reference to the UIATarget pointing to the current target. These are provided to avoid extraneous the boilerplate code required by every UIAutomation test.

Test Function Bodies

UIAutomation tests typically alternate between exercising the UI in some fashion, then making assertions about its current presentation and state. You exercise the UI using UIAutomation’s built-in API, you validate the UI using tuneup’s library of assertions.

Grouping Tests

You can declare as many tests in a single file as you see fit. However, for maintenance and readability reasons, you should consider grouping tests into a single file that all relate to the same feature of the application. For example, you may have a login screen to your application that needs to be tested when a user successfully logs in, unsuccessfully logs in and when the backend server is unavailable. You could structure each of these cases in separate test declarations all within a single file.