Writing Tests

Learn how to write UIAutomation tests using Tuneup JS

One of tuneup’s primary goals is making tests as easy to read as they are easy to write. This is done by grouping actions and assertions together in logical testing units. These tests are idenfitied by a call to the test JavaScript function. In order for you to use this function, you need to import tuneup into the JavaScript runtime.

UIAutomation does most of the heavy lifting, but tuneup refines the interface for a more pleasant experience. Just keep in mind that, under the covers, it’s all UIAutomation.

Step 1: Import Tuneup JS

To import tuneup, use the #import statement provided by UIAutomation’s JavaScript runtime. The exact path you use will depend on where your tests are located and how you’ve installed tuneup.

Let’s assume that you have a directory for your tests located in integration at the root of your project file. If you installed it using CocoaPods, then your import statement will look like this:

#import "../Pods/tuneup_js/tuneup.js"

If you’ve installed tuneup manually, then you will need to figure out the correct path to the tunup.js file.

Step 2: Declare a Test

In your test file, the next thing you need to do is declare a new test using the test function. The function takes two arguments: a string title for your test and a JavaScript function that accepts two parameters named target and app.

test("Login screen", function(target, app) {
  // do cool stuff in here

Step 3: Exercise and Validate

Once you have a test declared, you fill the body of the function with JavaScript statements to exercise the UI using the UIAutomation API, and validate the state and behavior of the application using tuneup’s assertion functions.

test("Login screen", function(target, app) {
  var window = app.mainWindow();

  // tap the left button in the navigation bar

  // now assert that the app has navigated into a sub-view controller
  assertEquals("Settings", window.navigationBars()[0].value());

Once you’ve written your test, it’s time to run it.