I use Xamarin Forms for my app on Android. I want test the app after event OnSleep and OnResume with unit test. Is it posible?
@FetFrumos911 - Using Xamarin UITest to test lifecycle events requires lateral thinking. It's a while since I used UITest, but I definitely had this working.
As a reminder, here's what the documentation says at https://developer.xamarin.com/guides/xamarin-forms/working-with/app-lifecycle/ for the different events:
OnStart - Called when the application starts.
OnSleep - Called each time the application goes to the background.
OnResume - Called when the application is resumed, after being sent to the background.
If I remember correctly (I haven't got the code in front of me right now), when my app was in background, I think calling StartApp again resulted in OnResume being fired. Of course, your app may be terminated when it is in background, so you might want to mutate your app code slightly so that you can check whether OnStart or OnResume is called and try again as required.
To get the app to background, simply bring another app to the foreground. My app has the ability to open a page in an external browser by tapping on a hyperlink. To get OnSleep to fire, I simply tapped on that hyperlink. If you app doesn't have anything similar, you could add a backdoor for testing purposes (see https://developer.xamarin.com/guides/testcloud/uitest/working-with/backdoors/ )
thank you very much. you have shown the way.
I use backdoor. I opened link in browser. I need return to app. Is it possible?
@ZenDroid - Yes - call StartApp again. using AppDataMode.DoNotClear . If I remember correctly, StartApp will bring a backgrounded app back to the foreground. I don't think it's documented, but my memory tells me that's what I found.
Thank you. It is work.
Xamarin Inc., as a wholly-owned Microsoft subsidiary acting as a separate legal entity, adheres to the Microsoft Privacy Statement: Privacy & cookies