Autopilot is a tool for writing functional tests. Functional tests are tests that:
Autopilot was designed to test the Unity 3D shell. However, since then it has been used to test a number of other applications, including:
Autopilot exists at the apex of the “testing pyramid”. It is designed to test high-level functionality, and complement a solid base of unit and integration tests. Using autopilot is not a substitute for testing your application with unit and integration tests!. Autopilot is a very capable tool for testing high-level feature functionality. It is not an appropriate tool for testing low-level implementation details.
Autopilot is built on top of several other python test frameworks, including:
A typical autopilot test has three distinct stages:
The Setup Stage
There are several concerns that must be addressed in the setup Phase. The most important step is to launch the application to be tested. Most autopilot test suites launch the application under test anew for each test. This ensures that the test starts with the application under test in a known, clean state. Autopilot can launch normal applications, launch applications via upstart, or launch apps contained within a click package.
Tests may also wish to take other actions in the setup stage, including:
The purpose of the setup stage is to make sure that everything that is required for the test to run is in place.
The Interaction Stage
Once the setup has been completed, it’s time to start interacting with your application. This typically involves generating input events. For example, if you are testing a text editor you might have a test whose specification is similar to the following:
Type some text into the document area, open the 'Edit' menu and click
the 'Search and Replace' menu item.
During this stage you will most likely need to read the applications internal state. For example, your test will need to know where the ‘Edit’ menu is on the screen. Thankfully, autopilot takes care of the details, allowing you to write expressive tests.
The Assertion Stage
The final stage is where you determine if your test should pass or fail. Most tests will contain more than one assertion (why?). Autopilot contains several custom assertions that make testing high-level concepts easier.