austgl / robotium

Automatically exported from code.google.com/p/robotium
0 stars 0 forks source link

startActivityForResult from onCreate() stack isn't tracked #111

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create activity A
2. startActivityForResult for activity B (in same app)
3. Write Test case for A. In test, write:
    solo.waitForActivity("B", 30);
    ArrayList<Activity> activities = solo.getAllOpenedActivities();
    Activity a = solo.getCurrentActivity();

Phone shows activity B correctly, but the test case will return A as the 
current activity (and as the only opened activity), even though B is clearly on 
the screen and other methods (like getCurrentListViews()) will return the 
correct views from activity B.

What version of the product are you using? On what operating system?

Robotium 2.3, OSX 10.6, Testing using Android 1.6 and 2.2 devices.

Original issue reported on code.google.com by tony....@gmail.com on 6 May 2011 at 2:53

GoogleCodeExporter commented 9 years ago
Try startActivitySync(Intent intent) instead.

Original comment by renasr...@gmail.com on 6 May 2011 at 5:02

GoogleCodeExporter commented 9 years ago

Original comment by renasr...@gmail.com on 6 May 2011 at 5:02

GoogleCodeExporter commented 9 years ago

Original comment by renasr...@gmail.com on 10 May 2011 at 5:59

GoogleCodeExporter commented 9 years ago
The point is that activity A needs to start B (which are both in the same app), 
and B will return a result. The test is not starting it, A is. The whole point 
of the test is that A starts B, and then gets back a result. I can use other 
methods to see the appropriate screen details synchronously, so that isn't the 
problem.

That said, I can deduce the activity is running, and I can deduce that it has 
returned. My report wasn't that I could not _write_ the test, it was simply 
that stating assertions related to the "current activity" are useless if you 
don't actually _track_ the current activity...so then why have such methods in 
your public interface?

This is not an invalid issue. It is a bug. The public facing API of you classes 
doesn't work.

The documentation of the activity related methods should at least contain this:

NOTE: These methods cannot track the current activity if your code uses 
startActivityForResult(). You should invent some other way of testing such 
activity flow (e.g. examine what is on the screen).

Original comment by tony....@gmail.com on 10 May 2011 at 3:39

GoogleCodeExporter commented 9 years ago
Please note: you need to implement tearDown methods for the tests, like this:
    @Override
    public void tearDown() throws Exception {
        solo.finishOpenedActivities();
        super.tearDown();
    }
If you skip it, it may lead to the described behavior.
(I'm not saying the issue is valid or invalid)

Original comment by kovmarc...@gmail.com on 20 Mar 2014 at 3:44