- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 robotium 执行单元测试......每次我尝试我都会得到一个空指针异常......一切都很好,直到应用程序加载然后发生异常......在教程中据说这是会出现错误,但解决方案不清楚..请帮助..代码如下:
package com.testCalculator;
import android.test.ActivityInstrumentationTestCase2;
import com.jayway.android.robotium.solo.Solo;
@SuppressWarnings("unchecked")
public class TestApk extends ActivityInstrumentationTestCase2 {
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.calculator.Main";
private static Class launcherActivityClass;
static {
try {
launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
}
catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public TestApk() throws ClassNotFoundException {
super(launcherActivityClass);
}
private Solo solo;
@Override
protected void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
public void testDisplayBlackBox() {
// Enter any integer/decimal value for first edit-field, we are writing 10
solo.clearEditText(0);
solo.enterText(0, "10");
// Enter any integer/decimal value for first edit-field, we are writing 20
solo.clearEditText(1);
solo.enterText(1, "20");
// Tap on Multiply button
solo.clickOnButton("Multiply");
//Assert that the correct resultant of 10 x 20 is returned
assertTrue("Problem asserting multiply", solo.searchText("200"));
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}
}
黑盒测试失败跟踪:
TestApk (2)
samsung-samsung_sm_n900a-a0964e35
com.testCalculator.TestApk
testDisplayBlackBox (com.testCalculator.TestApk) [samsung-samsung_sm_n900a-a0964e35]
java.lang.NullPointerException
at com.jayway.android.robotium.solo.ViewFetcher.getNonDecorViews(ViewFetcher.java:163)
at com.jayway.android.robotium.solo.ViewFetcher.getAllViews(ViewFetcher.java:85)
at com.jayway.android.robotium.solo.ViewFetcher.getViews(ViewFetcher.java:194)
at com.jayway.android.robotium.solo.ViewFetcher.getCurrentViews(ViewFetcher.java:312)
at com.jayway.android.robotium.solo.ViewFetcher.getCurrentViews(ViewFetcher.java:299)
at com.jayway.android.robotium.solo.Searcher.searchFor(Searcher.java:123)
at com.jayway.android.robotium.solo.Waiter.waitForView(Waiter.java:105)
at com.jayway.android.robotium.solo.Waiter.waitForAndGetView(Waiter.java:348)
at com.jayway.android.robotium.solo.Solo.enterText(Solo.java:1290)
at com.testCalculator.TestApk.testDisplayBlackBox(TestApk.java:29)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1741)
日志猫输出:
07-18 10:36:28.084: I/dalvikvm(31894): Enabling JNI app bug workarounds for target SDK version 8...
07-18 10:36:28.134: I/TestRunner(31894): started: testDisplayBlackBox(com.testCalculator.TestApk)
07-18 10:36:28.154: I/TestRunner(31894): finished: testDisplayBlackBox(com.testCalculator.TestApk)
07-18 10:36:28.154: I/TestRunner(31894): passed: testDisplayBlackBox(com.testCalculator.TestApk)
07-18 10:36:28.924: I/dalvikvm(31977): Enabling JNI app bug workarounds for target SDK version 8...
07-18 10:36:28.964: I/TestRunner(31977): started: testDisplayBlackBox(com.testCalculator.TestApk)
07-18 10:36:29.014: W/ApplicationPackageManager(31977): getCSCPackageItemText()
07-18 10:36:29.124: I/Adreno-EGL(31977): <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: ()
07-18 10:36:29.124: I/Adreno-EGL(31977): OpenGL ES Shader Compiler Version: E031.24.00.07
07-18 10:36:29.124: I/Adreno-EGL(31977): Build Date: 01/22/14 Wed
07-18 10:36:29.124: I/Adreno-EGL(31977): Local Branch: base_au149_adreno_au169_patches
07-18 10:36:29.124: I/Adreno-EGL(31977): Remote Branch:
07-18 10:36:29.124: I/Adreno-EGL(31977): Local Patches:
07-18 10:36:29.124: I/Adreno-EGL(31977): Reconstruct Branch:
07-18 10:36:29.164: D/OpenGLRenderer(31977): Enabling debug mode 0
07-18 10:36:29.254: V/RenderScript(31977): Application requested CPU execution
07-18 10:36:29.254: V/RenderScript(31977): 0x78878260 Launching thread(s), CPUs 4
07-18 10:36:29.274: E/dalvikvm(31977): Could not find class 'android.support.v4.app.FragmentActivity', referenced from method com.jayway.android.robotium.solo.Waiter.getSupportFragment
07-18 10:36:29.274: W/dalvikvm(31977): VFY: unable to resolve check-cast 21 (Landroid/support/v4/app/FragmentActivity;) in Lcom/jayway/android/robotium/solo/Waiter;
07-18 10:36:29.274: D/dalvikvm(31977): VFY: replacing opcode 0x1f at 0x0009
07-18 10:36:29.274: I/dalvikvm(31977): Could not find method android.support.v4.app.FragmentActivity.getSupportFragmentManager, referenced from method com.jayway.android.robotium.solo.Waiter.getSupportFragment
07-18 10:36:29.274: W/dalvikvm(31977): VFY: unable to resolve virtual method 26: Landroid/support/v4/app/FragmentActivity;.getSupportFragmentManager ()Landroid/support/v4/app/FragmentManager;
07-18 10:36:29.274: D/dalvikvm(31977): VFY: replacing opcode 0x6e at 0x0010
07-18 10:36:29.274: I/dalvikvm(31977): Could not find method android.support.v4.app.FragmentActivity.getSupportFragmentManager, referenced from method com.jayway.android.robotium.solo.Waiter.getSupportFragment
07-18 10:36:29.274: W/dalvikvm(31977): VFY: unable to resolve virtual method 26: Landroid/support/v4/app/FragmentActivity;.getSupportFragmentManager ()Landroid/support/v4/app/FragmentManager;
07-18 10:36:29.274: D/dalvikvm(31977): VFY: replacing opcode 0x6e at 0x0019
07-18 10:36:29.274: W/dalvikvm(31977): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
07-18 10:36:29.274: W/dalvikvm(31977): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
07-18 10:36:29.774: W/System.err(31977): java.lang.NoSuchFieldException: mViews
07-18 10:36:29.784: W/System.err(31977): at java.lang.Class.getDeclaredField(Class.java:596)
07-18 10:36:29.784: W/System.err(31977): at com.jayway.android.robotium.solo.ViewFetcher.getWindowDecorViews(ViewFetcher.java:382)
07-18 10:36:29.784: W/System.err(31977): at com.jayway.android.robotium.solo.ViewFetcher.getAllViews(ViewFetcher.java:83)
07-18 10:36:29.784: W/System.err(31977): at com.jayway.android.robotium.solo.ViewFetcher.getViews(ViewFetcher.java:194)
07-18 10:36:29.784: W/System.err(31977): at com.jayway.android.robotium.solo.ViewFetcher.getCurrentViews(ViewFetcher.java:312)
07-18 10:36:29.784: W/System.err(31977): at com.jayway.android.robotium.solo.ViewFetcher.getCurrentViews(ViewFetcher.java:299)
07-18 10:36:29.784: W/System.err(31977): at com.jayway.android.robotium.solo.Searcher.searchFor(Searcher.java:123)
07-18 10:36:29.784: W/System.err(31977): at com.jayway.android.robotium.solo.Waiter.waitForView(Waiter.java:105)
07-18 10:36:29.784: W/System.err(31977): at com.jayway.android.robotium.solo.Waiter.waitForAndGetView(Waiter.java:348)
07-18 10:36:29.784: W/System.err(31977): at com.jayway.android.robotium.solo.Solo.clearEditText(Solo.java:1339)
07-18 10:36:29.784: W/System.err(31977): at com.testCalculator.TestApk.testDisplayBlackBox(TestApk.java:27)
07-18 10:36:29.784: W/System.err(31977): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 10:36:29.794: W/System.err(31977): at java.lang.reflect.Method.invoke(Method.java:515)
07-18 10:36:29.794: W/System.err(31977): at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
07-18 10:36:29.794: W/System.err(31977): at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
07-18 10:36:29.794: W/System.err(31977): at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
07-18 10:36:29.794: W/System.err(31977): at junit.framework.TestCase.runBare(TestCase.java:134)
07-18 10:36:29.794: W/System.err(31977): at junit.framework.TestResult$1.protect(TestResult.java:115)
07-18 10:36:29.794: W/System.err(31977): at junit.framework.TestResult.runProtected(TestResult.java:133)
07-18 10:36:29.794: W/System.err(31977): at junit.framework.TestResult.run(TestResult.java:118)
07-18 10:36:29.794: W/System.err(31977): at junit.framework.TestCase.run(TestCase.java:124)
07-18 10:36:29.794: W/System.err(31977): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
07-18 10:36:29.794: W/System.err(31977): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
07-18 10:36:29.794: W/System.err(31977): at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
07-18 10:36:29.794: W/System.err(31977): at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1741)
07-18 10:36:29.994: W/IInputConnectionWrapper(31977): showStatusIcon on inactive InputConnection
07-18 10:36:30.734: I/TestRunner(31977): failed: testDisplayBlackBox(com.testCalculator.TestApk)
07-18 10:36:30.734: I/TestRunner(31977): ----- begin exception -----
07-18 10:36:30.734: I/TestRunner(31977): java.lang.NullPointerException
07-18 10:36:30.734: I/TestRunner(31977): at com.jayway.android.robotium.solo.ViewFetcher.getNonDecorViews(ViewFetcher.java:163)
07-18 10:36:30.734: I/TestRunner(31977): at com.jayway.android.robotium.solo.ViewFetcher.getAllViews(ViewFetcher.java:85)
07-18 10:36:30.734: I/TestRunner(31977): at com.jayway.android.robotium.solo.ViewFetcher.getViews(ViewFetcher.java:194)
07-18 10:36:30.734: I/TestRunner(31977): at com.jayway.android.robotium.solo.ViewFetcher.getCurrentViews(ViewFetcher.java:312)
07-18 10:36:30.734: I/TestRunner(31977): at com.jayway.android.robotium.solo.ViewFetcher.getCurrentViews(ViewFetcher.java:299)
07-18 10:36:30.734: I/TestRunner(31977): at com.jayway.android.robotium.solo.Searcher.searchFor(Searcher.java:123)
07-18 10:36:30.734: I/TestRunner(31977): at com.jayway.android.robotium.solo.Waiter.waitForView(Waiter.java:105)
07-18 10:36:30.734: I/TestRunner(31977): at com.jayway.android.robotium.solo.Waiter.waitForAndGetView(Waiter.java:348)
07-18 10:36:30.734: I/TestRunner(31977): at com.jayway.android.robotium.solo.Solo.clearEditText(Solo.java:1339)
07-18 10:36:30.734: I/TestRunner(31977): at com.testCalculator.TestApk.testDisplayBlackBox(TestApk.java:27)
07-18 10:36:30.734: I/TestRunner(31977): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 10:36:30.734: I/TestRunner(31977): at java.lang.reflect.Method.invoke(Method.java:515)
07-18 10:36:30.734: I/TestRunner(31977): at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
07-18 10:36:30.734: I/TestRunner(31977): at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
07-18 10:36:30.734: I/TestRunner(31977): at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
07-18 10:36:30.734: I/TestRunner(31977): at junit.framework.TestCase.runBare(TestCase.java:134)
07-18 10:36:30.734: I/TestRunner(31977): at junit.framework.TestResult$1.protect(TestResult.java:115)
07-18 10:36:30.734: I/TestRunner(31977): at junit.framework.TestResult.runProtected(TestResult.java:133)
07-18 10:36:30.734: I/TestRunner(31977): at junit.framework.TestResult.run(TestResult.java:118)
07-18 10:36:30.734: I/TestRunner(31977): at junit.framework.TestCase.run(TestCase.java:124)
07-18 10:36:30.734: I/TestRunner(31977): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
07-18 10:36:30.734: I/TestRunner(31977): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
07-18 10:36:30.734: I/TestRunner(31977): at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
07-18 10:36:30.734: I/TestRunner(31977): at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1741)
07-18 10:36:30.734: I/TestRunner(31977): ----- end exception -----
07-18 10:36:30.734: I/TestRunner(31977): finished: testDisplayBlackBox(com.testCalculator.TestApk)
控制台输出:
Android Launch!
[2014-07-18 10:36:09 - TestCalculator] adb is running normally.
[2014-07-18 10:36:09 - TestCalculator] Performing android.test.InstrumentationTestRunner JUnit launch
[2014-07-18 10:36:09 - TestCalculator] Automatic Target Mode: Unable to detect device compatibility. Please select a target device.
[2014-07-18 10:36:11 - TestCalculator] Uploading TestCalculator.apk onto device 'a0964e35'
[2014-07-18 10:36:11 - TestCalculator] Installing TestCalculator.apk...
[2014-07-18 10:36:16 - TestCalculator] Success!
[2014-07-18 10:36:16 - TestCalculator] Project dependency found, installing: AndroidCalculator
[2014-07-18 10:36:16 - AndroidCalculator] Uploading AndroidCalculator.apk onto device 'a0964e35'
[2014-07-18 10:36:16 - AndroidCalculator] Installing AndroidCalculator.apk...
[2014-07-18 10:36:27 - AndroidCalculator] Success!
[2014-07-18 10:36:27 - TestCalculator] Launching instrumentation android.test.InstrumentationTestRunner on a0964e35
[2014-07-18 10:36:28 - TestCalculator] Sending test information to Eclipse
[2014-07-18 10:36:31 - TestCalculator] Test run finished
最佳答案
您使用的是旧版本的 Robotium。请更新到 5.2.1 就不会出现这个问题了。
关于java - 空指针异常 - Robotium 单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24828722/
我已经为使用 JGroups 编写了简单的测试。有两个像这样的简单应用程序 import org.jgroups.*; import org.jgroups.conf.ConfiguratorFact
我有一个通过 ajax 检索的 json 编码数据集。我尝试检索的一些数据点将返回 null 或空。 但是,我不希望将那些 null 或空值显示给最终用户,或传递给其他函数。 我现在正在做的是检查
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: Why does one often see “null != variable” instead of “
嗨在我们公司,他们遵循与空值进行比较的严格规则。当我编码 if(variable!=null) 在代码审查中,我收到了对此的评论,将其更改为 if(null!=variable)。上面的代码对性能有影
我正在尝试使用 native Cordova QR 扫描仪插件编译项目,但是我不断收到此错误。据我了解,这是代码编写方式的问题,它向构造函数发送了错误的值,或者根本就没有找到构造函数。那么我该如何解决
我在装有 Java 1.8 的 Windows 10 上使用 Apache Nutch 1.14。我已按照 https://wiki.apache.org/nutch/NutchTutorial 中提
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: what is “=null” and “ IS NULL” Is there any difference bet
Three-EyedRaven 内网渗透初期,我们都希望可以豪无遗漏的尽最大可能打开目标内网攻击面,故,设计该工具的初衷是解决某些工具内网探测速率慢、运行卡死、服务爆破误报率高以及socks流
我想在Scala中像在Java中那样做: public void recv(String from) { recv(from, null); } public void recv(String
我正在尝试从一组图像补丁中创建一个密码本。我已将图像(Caltech 101)分成20 X 20图像块。我想为每个补丁创建一个SIFT描述符。但是对于某些图像补丁,它不返回任何描述符/关键点。我尝试使
我在验证器类中自动连接的两个服务有问题。这些服务工作正常,因为在我的 Controller 中是自动连接的。我有一个 applicationContext.xml 文件和 MyApp-servlet.
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 已关闭10 年前。 问题必须表现出对要解决的问题的最低程度的了解。告诉我们您尝试过做什么,为什么不起作用,以
大家好,我正在对数据库进行正常的选择,但是 mysql_num_rowsis 为空,我不知道为什么,我有 7 行选择。 如果您发现问题,请告诉我。 真的谢谢。 代码如下: function get_b
我想以以下格式创建一个字符串:id[]=%@&stringdata[]=%@&id[]=%@&stringdata[]=%@&id[]=%@&stringdata[]=%@&等,在for循环中,我得到
我正在尝试使用以下代码将URL转换为字符串: NSURL *urlOfOpenedFile = _service.myURLRequest.URL; NSString *fileThatWasOpen
我正在尝试将NSNumber传递到正在工作的UInt32中。然后,我试图将UInt32填充到NSData对象中。但是,这在这里变得有些时髦... 当我尝试将NSData对象中的内容写成它返回的字符串(
我正在进行身份验证并收到空 cookie。我想存储这个 cookie,但服务器没有返回给我 cookie。但响应代码是 200 ok。 httpConn.setRequestProperty(
我认为 Button bTutorial1 = (Button) findViewById(R.layout.tutorial1); bTutorial1.setOnClickListener
我的 Controller 中有这样的东西: model.attribute("hiringManagerMap",hiringManagerMap); 我正在访问此 hiringManagerMap
我想知道如何以正确的方式清空列表。在 div 中有一个列表然后清空 div 或列表更好吗? 我知道这是一个蹩脚的问题,但请帮助我理解这个 empty() 函数:) 案例)如果我运行这个脚本会发生什么:
我是一名优秀的程序员,十分优秀!