Using Instrumentation during ActivityInstrumentationTestCase

by James » Tue, 23 Dec 2008 22:17:34 GMT


Sponsored Links
 I'm running my ActivityInstrumentationTestCase.  it runs in the
emulator.  I can watch the Intents triggering Activities in 'adb
logcat".  I see in the logcat output that the Activity was displayed:

I/ActivityManager(   50): Displayed activity my.manifest.packate/
my.package.CountingActivity: 556 ms

so I believe I've sent the keys to press the button that fire the
startActivity.  What I'm not seeing is the monitor that I've added
through the test.  My waitForMonitorWithTimeout always times out.
Here is the part of the unit test that sets up the monitor, triggers
it, then waits:

                ActivityResult result = new ActivityResult(1, null);
                String activityClassName = "my.manifest.packate/
my.package.CountingActivity";
                ActivityMonitor monitor = getInstrumentation().addMonitor
(activityClassName, result, true);

                sendKeys(KeyEvent.KEYCODE_ENTER);

                System.out.println("wait for timeout");
                Activity actualActivity = getInstrumentation
().waitForMonitorWithTimeout(monitor, 20000);
                System.out.println("after timeout");
                assertNotNull("non null activity means the monitor was invoked",
actualActivity);

The activity implementation "CountingActivity" has a sysout, it always
prints in logcat after "wait for timeout" and before "after timeout",
but the actualActivity is always null.  I show here using the full
<package>/<full-class-name> for the activityClassName.  I began with
out the "<package>/" and used just the classname, but that had the
same effect -- never triggering the monitor.  Further evidence that
I'm not registering the monitor correctly is that that addMonitor call
with true at the end should skip the actual Activity and return my
canned result.

Has anyone successfully tested with this process?
--~--~---------~--~----~------------~-------~--~----~



Using Instrumentation during ActivityInstrumentationTestCase

by James » Tue, 30 Dec 2008 03:12:58 GMT


 I didn't get any responses from the "Android Beginners" group, so
after a few days wait I'm trying this group.  I'm trying to use the
provided methods on the Instrumentation instance given to
ActivityInstrumentationTestCase classes.  I could not find a book
listed on Amazon (available or pre-release) that covered unit
testing.  I scanned the table of contents of all the Android books I
found.  If you know of one, please point it out.

I'm running my ActivityInstrumentationTestCase.  it runs in the
emulator.  I can watch the Intents triggering Activities in 'adb
logcat".  I see in the logcat output that the Activity was displayed:

I/ActivityManager(   50): Displayed activity my.manifest.package/
my.package.CountingActivity: 556 ms

so I believe I've sent the keys to press the button that fire the
startActivity.  What I'm not seeing is the monitor that I've added
through the test.  My waitForMonitorWithTimeout always times out.
Here is the part of the unit test that sets up the monitor, triggers
it, then waits:

                ActivityResult result = new ActivityResult(1, null);
                String activityClassName = "my.manifest.packate/
my.package.CountingActivity";
                ActivityMonitor monitor = getInstrumentation
().addMonitor
(activityClassName, result, true);

                sendKeys(KeyEvent.KEYCODE_ENTER);

                System.out.println("wait for timeout");
                Activity actualActivity = getInstrumentation
().waitForMonitorWithTimeout(monitor, 20000);
                System.out.println("after timeout");
                assertNotNull("non null activity means the monitor was
invoked",
actualActivity);

The activity implementation "CountingActivity" has a sysout, it always
prints in logcat after "wait for timeout" and before "after timeout",
but the actualActivity is always null.  I show here using the full
<package>/<full-class-name> for the activityClassName.  I began with
out the "<package>/" and used just the classname, but that had the
same effect -- never triggering the monitor.  Further evidence that
I'm not registering the monitor correctly is that that addMonitor call
with true at the end should skip the actual Activity and return my
canned result.

Has anyone successfully tested with these methods from
Instrumentation?

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. battery percent on desire

Disuruh login (T_T)

-- 
"Indonesian Android Community [id-android]" 

2. Do threads cache instance variables?

Hi,

I am starting to develop an Android App and have noticed the following
behaviour in my test code (not yet designed the real app):

A thread that loops around doing Bluetooth IO accesses an instance
variable that is declared in the enclosing class. That instance
variable gets set to null by the GUI thread in the onBackPressed()
method which also closes the Bluetooth socket which causes an
exception in the IO thread (which is what I want).

The odd thing is that if I set the instance variable to null before I
close the socket, the IO thread sees the null value, but if I close
the socket first and then set the variable to null, the IO thread
doesn't see the null value.

The instance variable is being used in a loop in the IO thread and it
appears as if that variable is being cached while within the loop. So
any changes to that variable by another thread are not visible. Is
that possible? If so, is there a workaround to guarantee that the VM
will read the value of the instance variable?

Cheers,

Mark

-- 

3. Passing an int value from one activity to another

4. JDK and Eclipse installation

5. Simpler way unlock MSL Code HTC EVO 4G

6. println needs a message

7. oot jerman spanyol