编译我的代码后,我得到了这个例外
java.lang.IllegalStateException
:没有注册仪器!必须在注册仪器下运行。
我正在使用带有ADT插件的eclipse IDE。
import android.support.test.uiautomator.*;
import android.support.test.InstrumentationRegistry;
import android.support.test.internal.runner.junit3.*;
import android.support.test.internal.runner.listener.InstrumentationResultPrinter;
import android.support.test.rule.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import android.os.RemoteException;
import android.support.*;
@RunWith(JUnit4.class)
public class uia {
private UiDevice d;
@Before
public void setup() throws RemoteException {
d = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
d.isScreenOn();
}
@Test
public void home(){
d.pressHome();
}
}
运行此代码后,我得到以下跟踪:
java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation.
at android.support.test.InstrumentationRegistry.getInstrumentation(InstrumentationRegistry.java:45)
at ui.uia.setup(uia.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
有什么建议吗?