You cannot simulate a press of the home button, but you can force the application to exit as if it were. Call [[UIApplication sharedApplication] terminate]; will end or (in the case of iOS 4.x) the background of the application. However, you cannot restart the application using UIAutomation.
You can try UIAutomation in conjunction with an on-screen recording script that allows you to play back mouse movements and clicks. This will allow you to interact directly with the simulator for things such as clicks on the home button and clicks on application icons.
Alternatively, you can get "fairly good" testing using the UIATarget class. In documents
The UIATarget class represents the high-level user interface of the system under test (SUT), that is, your application, iOS, and the connected device on which they work. Your test scripts, written in JavaScript and working in conjunction with the Automation Tool user interface, use this class and its UIA classes to execute SUT and log results.
Using UIATarget.localTarget().deactivateAppForDuration(seconds); , you can create your application in a few seconds.
Use this method to check the porting of the application to and from the background execution context. Please note that applications created using iOS SDK 4.0 or later and work in iOS 4.0 and later if the user clicks the Home button. See the iOS App Programming Guide for details on multitasking and background execution context.
source share