I have one normal android package with an activity A.
Now I am using a second independent test package in which I run several tests.
for testing purposes i want to create an activity B which extends the activity A,
in order to overwrite some aspects of A for testing.
but since activity B is only for testing purposes I want to keep it in the test package.
Is there any possible way for this?
Related
Android Espresso testing app flow
I use Espresso to test a lot of activities and transitions between them. I want to write different test for those activities and link the Activity Intents to the corresponding test cases.
1 . Activity A (testActivityA runs) 2. ActivityA launches ActivityB (testActivity B) should be called
is it possible to do this with espresso or any other test framework?
You should test each activity independently of the others. If you need them to react to incoming intents, you can do that using Espresso Intents.
I use Espresso to test a lot of activities and transitions between them. I want to write different test for those activities and link the Activity Intents to the corresponding test cases.
1 . Activity A (testActivityA runs)
2. ActivityA launches ActivityB (testActivity B) should be called
is it possible to do this with espresso or any other test framework?
When writing an android test case how can I call some methods on my application object before the activity is created? My test class extends ActivityInstrumentationTestCase2.
Some of the things I've tried are
Looking for a method my test case can override. I don't see one.
Creating a test activity that extends the app's activity. I dont think I can do this without adding the test activity to the real application's manifest.
Getting the application inside of my test's setUp() method. I can't find any way to access the application without first creating the activity
You can't do what you're trying to do. ActivityInstrumentationTestCase2 is not designed to do it. You need something like Robotium that can invoke your Application object first, before your Activity object is created.
ActivityInstrumentationTestCase2, except in a few cases, is designed to test things within the Activity, and not its interaction with things outside the Activity. Unit testing in Android isn't perfect.
I also question why you need something from Application. Whenever someone mentions Application, a warning light goes off in my head. I rarely see code that uses Application, and 90% of the time the developer should have used something else.
I am new for Junit testing framework. Is it possible to test a flow of activities with assertions to check if each is launched using only exisiting classes provided in android API.
It seems we can only test at activity level. But can we automate a flow : like spawning front and back between activities ?
Yes, through the use of Android instrumentation, which provides you with methods that put you into the drivers seat when interacting with activities as the system would through it's instrumentation framework.
Basically, your able to trigger and manage every aspect of an activities life cycle, including introspecting results from activities calling each other. So if you've worked with the ActivityTestCase that's suitable when testing a single activity, you can have a look at the InstrumentationTestCase that provides you with a low-level approach to work with multiple activities at once.
i have a main activity and when tap on the button in the main activity it moves to the another activity than runs on another process .. is there a chance to track/get that activity using robotium /by means of other codes to integrate with robotium
Unfortunately no. Robotium builds upon Android's instrumentation objects which are limited to work only within the process of the instrumentation for the given target Activity (as you define a target process in the test-manifest file).
I don't know how it behaves in cases where the target process has a defined shared user id, though...