English 中文(简体)
TouchUtils with Emulator
原标题:TouchUtils with Android Emulator

Has anyone been able to successfully perform unit testing on the Android Emulator using methods offered by the TouchUtils class?
I m able to get the test(s) to pass on my device but when I run the exact same test(s) (and test suite) on an emulator, any test using a TouchUtils methods always throws the following exception:

java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
at android.os.Parcel.readException(Parcel.java:1327)
at android.os.Parcel.readException(Parcel.java:1281)
at android.view.IWindowManager$Stub$Proxy.injectPointerEvent(IWindowManager.java:1196)
at android.app.Instrumentation.sendPointerSync(Instrumentation.java:902)
at android.test.TouchUtils.drag(TouchUtils.java:786)
at android.test.TouchUtils.dragViewTo(TouchUtils.java:633)
...

I ve unlocked the keyguard and even ran other (non TouchUtils) test cases which have passed.
I do not have the @UiThreadTest applied nor am I running anything that requires code to run on the UI thread.
When I comment out the line that employs TouchUtils.dragViewTo(...) and put in a simple assert(true), the test runs and passes.

任何想法?

问题回答

如果你的电话被锁定,或者在家中还有其他一些活动,就会出现这种情况。

The emulator is so slow, that when you emulate a UI interaction after you dismiss the virtual keyboard, there isn t enough time for the virtual keyboard to dismiss and so you are actually injecting events into the virtual keyboard and not your application.

在你躲藏软键板之后,在你试图进行任何“国际倡议”互动之前,就睡在你们的read子上约500-1000米。

try {
    Thread.sleep(500);
} 
catch (InterruptedException e) {
    e.printStackTrace();
}




相关问题
run unit tests and coverage in certain python structure

I have some funny noob problem. I try to run unit tests from commandline: H:PROpyEstimator>python src estpython est_power_estimator.py Traceback (most recent call last): File "src est...

How to unit-test an enterprise symfony project?

I´m working on a huge project at my work. We have about 200 database tables, accordingly a huge number of Models, Actions and so on. How should I begin to write tests for this? My biggest problem ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Unit testing. File structure

I have a C++ legacy codebase with 10-15 applications, all sharing several components. While setting up unittests for both shared components and for applications themselves, I was wondering if there ...

Unit Testing .NET 3.5 projects using MStest in VS2010

There s a bug/feature in Visual Studio 2010 where you can t create a unit test project with the 2.0 CLR. https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=483891&wa=...

Unit Test for Exceptions Message

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() ...

热门标签