Information Technology Reference
In-Depth Information
Instruments works by adding a custom action to each probe, which runs when the probe “fires”—in other words,
when some relevant event triggers it. You can script your own actions, although you need to have some under-
standing of each probe and its options.
You don't need to use or understand DTrace to use Instruments, but it can be useful to incorporate DTrace features
into command-line development. A full introduction to the scripting syntax is outside the scope of this topic. De-
fault scripts are available in /usr/bin. In Terminal, type the following to see a list of scripts that you can reverse-en-
gineer:
grep -l DTrace /usr/bin/*
More information is available at wikis.sun.com/display/DTrace/Documentation .
Although this kind of low-level exploration of DTrace is better suited to experienced programmers than beginners,
it can give almost everyone some insights into how DTrace can be used to monitor application and process activ-
ity.
Working with UIAutomation
It's often useful to send a sequence of test events to an app to check the UI for various possible errors and fail
states. Instruments includes an Automation script player that can read a set of automation and test events from
a file and send them as actions to an iOS app.
Test scripts are written in JavaScript and use the UIAutomation class. UIKit objects have a library of associ-
ated UIAutomation objects that can receive automation events. You can find the full list of objects in the UI
Automation Reference Collection in the Xcode documentation.
Test scripts can be simple, or extremely complex. It's up to you to decide how you want to test your UI. The fol-
lowing example is very simple indeed, but illustrates the process of testing and can be expanded to create a
more sophisticated test suite.
It's tempting to leave testing to the end of the development cycle, but it can be more productive to develop your
test script as you develop. Testing adds some overhead, but if you combine automated testing with the unit test-
ing described in Chapter 17 you can create a useful test suite that exercises the key features of your project and
helps ensure that features aren't broken by updates and bug fixes.
TIP
Most UI objects are subclasses of UIAElement . The documentation for UIAElement lists the messages you can
send to objects as you test them. It's a good place to start when you begin using UIAutomation . (If you look at
the object subclasses themselves, you won't find much of interest.)
NOTE
 
Search WWH ::




Custom Search