Chapter 3. Creating a Test Workbench

If there is one comfortable technique to which we HTML, CSS, and JavaScript developers have grown accustomed, it is writing some tiny code samples to test expression evaluations and execution logic. You very likely have at least one test.html file somewhere on your hard drive. In one of my JavaScript books, I include code for a page called The Evaluator, which allows readers (and, more importantly, me) to see values of single-line expressions and obtain property dumps of objects (lists of property names, values, and value types for any JavaScript or DOM object in the page).

It’s convenient to test code snippets initially in an environment that is isolated from your major work in progress. First, you don’t want other code to influence your experiment (think “scientific method”). Second, you don’t want your experiments to mess up your existing working code. The Workbench app you will build in this chapter will provide you with a running iPhone environment (initially on the iPhone Simulator) in which you can easily test expressions, logic, and the like. Use it as a learning lab while you work through the remaining chapters of this book.

Figure 3-1 shows the finished app. True, it’s nothing more than an iPhone screen with a button on it. You will set up this app so that you can test your code in the iPhone OS runtime environment by clicking that button. Results will appear in a separate window of Xcode, called the Console (more about that later). The ...

Get Learning the iOS 4 SDK for JavaScript Programmers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.