试图运行琐碎的Andr​​oid JUnit测试。入门:"试运行失败:没有测试结果与QUOT;我在想什么? [英] Trying to run trivial Android JUnit tests. Getting: "Test run failed: No test results" What am I missing?

查看:887
本文介绍了试图运行琐碎的Andr​​oid JUnit测试。入门:"试运行失败:没有测试结果与QUOT;我在想什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前从未使用JUnit的,现在我想将其设置在一个Android项目。

I have never used JUnit before, and now I'm trying to set it up on an Android project.

我的测试项目是相当复杂的,包括一些JNI,但我的测试项目,此刻,完全是微不足道的。我发现有很多的例子(看起来完全不同)如何让一个测试项目在线,但似乎我跟随无论是哪一个,我得到了相同的结果。

My project under test is fairly complex, including some JNI, but my test project, at the moment, is completely trivial. I have found many examples (that look totally different) online of how to make a test project, but it seems that no matter which one I follow, I get the same results.

下面是我的JUnit项目code:

Here's my JUnit project code:


package com.mycompany.myproject.test;

import android.test.AndroidTestCase;

public class SimpleTestCaseExample extends AndroidTestCase {
    public void test_testOne() {
        fail("Just Always Fail");
    }
}

当我跑,我看到下面的logcat的:

When I run, I see the following in Logcat:


stdout    INSTRUMENTATION_STATUS: numtests=2
stdout    INSTRUMENTATION_STATUS: test=test_testOne
stdout    INSTRUMENTATION_STATUS_CODE: 0
stdout    INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
stdout    INSTRUMENTATION_STATUS: current=2
stdout    INSTRUMENTATION_STATUS: class=com.mycompany.myproject.test.SimpleTestCaseExample
stdout    INSTRUMENTATION_STATUS: stream=
stdout    INSTRUMENTATION_STATUS: numtests=2
stdout    INSTRUMENTATION_STATUS: test=testAndroidTestCaseSetupProperly
stdout    INSTRUMENTATION_STATUS_CODE: 1
stdout    INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
stdout    INSTRUMENTATION_STATUS: current=2
stdout    INSTRUMENTATION_STATUS: class=com.mycompany.myproject.test.SimpleTestCaseExample
stdout    INSTRUMENTATION_STATUS: stream=.
stdout    INSTRUMENTATION_STATUS: numtests=2
stdout    INSTRUMENTATION_STATUS: test=testAndroidTestCaseSetupProperly
stdout    INSTRUMENTATION_STATUS_CODE: 0
stdout    INSTRUMENTATION_RESULT: stream=
stdout    Test results for InstrumentationTestRunner=..
stdout    Time: 0.07
stdout    OK (2 tests)
stdout    INSTRUMENTATION_CODE: -1

不过,我得到在控制台以下内容:

But, I get the following in the Console:


Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554
Collecting test information
Test run failed: No test results

我已经尝试了各种不同的东西,有基本的TestCase类,或TestSuite类,或各种其他选项搞乱。我想只是去最简单的例子,因为我真的还努力学习如何工作的。

I have tried a variety of different things, messing with the basic TestCase class, or the TestSuite class, or a variety of other options. I tried to just go for the most trivial example because I'm really still trying to learn how this works.

无论我试试,我看到这个错误。

Whatever I try, I see this error.

任何建议将是AP preciated!

Any suggestions would be appreciated!

如果我失去了一些重要的信息,请让我知道,我会更新。

If I'm missing some critical information, please let me know and I'll update.

推荐答案

OK,我想它了。

和很少有机会,任何人也能猜到是什么问题。我不知道是什么让我来试试吧。

And there is very little chance that anybody would have guessed what the problem is. I'm not sure what made me try it.

我有输出错误信息到标准输出一些JNI code。这code没有在我的测试项目运行,但是我用的是相同的模拟器。出于这个原因,我有一个/data/local.prop重定向标准输出到logcat中。

I have some JNI code that prints error messages to stdout. That code is not running in my test project, but I use the same emulator. For that reason, I had a /data/local.prop that redirects stdout to logcat.

原来,该测试工具期望从JUnit测试的输出出现在标准输出。当标准输出的logcat的重定向是上,没有结束对stdout和测试系统没有得到的输出,因此它无法运行。

It turns out that the test tools expect the output from the JUnit tests to appear on stdout. When the logcat redirect of stdout is on, nothing ends up on stdout, and the test system doesn't get the output, and so it fails to run.

我打消了我的local.prop标准输出到logcat中的重定向,并重新启动模拟器,而现在它的作品。

I removed my local.prop redirect of stdout to logcat, and rebooted the emulator, and now it works.

它永远不会发生在我的测试系统依靠阅读标准输出本身。

It never occurred to me that the test system relied upon reading stdout itself.

这篇关于试图运行琐碎的Andr​​oid JUnit测试。入门:"试运行失败:没有测试结果与QUOT;我在想什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆