android – Can I get the instrumentation test to kill and restart the app process?-ThrowExceptions

Exception or error:

I need to test a use case where the application starts from a clean state – i.e. the process has not been running before the test starts. From what I see from logcat, all instrumentation tests run under one single process instance/session, so the outcome of the test in my case depends on whether or not it runs as #1 or not. It should not be this way – as we all know, unit tests (or instrumentation tests) should be autonomous.

Is there any way with the standard Android instrumentation test tools and functions I can force the TestRunner to restart the process before a given test? If not, are there hacks or third-party libraries that can help me achieve that? Or is there any way I can specifically say that test X must be run first (worst option but still)?

In specific, my test relates to the launching of activities through intents, and the intent flags (e.g. FLAG_ACTIVITY_CLEAR_TOP) in addition to the Activity launch mode (e.g. singleTop) and the state of the process, very much dictates the outcome of the test.

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *