为什么Android的测试运行报告"空测试套件"? [英] Why is the Android test runner reporting "Empty test suite"?

查看:294
本文介绍了为什么Android的测试运行报告"空测试套件"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我撞我的头靠在墙上这里试图找出原因的IntelliJ / Android正在申报空测试套件。我有两个的IntelliJ模块(Eclipse中的项目)的一个小项目。单元测试模块有自己的Andr​​oidManifest.xml中,我已经贴在底部。我想运行一个 ActivityUnitTestCase ,因为测试将取决于上下文 -object。

I am banging my head against the wall here trying to figure out why IntelliJ/Android is reporting "Empty test suite". I have a small project with two IntelliJ Modules ("Projects" in Eclipse). The Unit test module has its own AndroidManifest.xml, which I have pasted at the bottom. I am trying to run an ActivityUnitTestCase, since the tests will be dependent upon the Context-object.

主要模块的封装名称为 nilzor.myapp <​​/ code>。测试模块的pacakge名称是 nilzor.myapp.tests

The package name of the main module is nilzor.myapp. The pacakge name of the test module is nilzor.myapp.tests

为什么不是测试运行检测 testBlah() -method作为测试?

Why is not the test runner detecting the testBlah()-method as a test?

<?xml version="1.0" encoding="utf-8"?>
<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="nilzor.myapp.tests"
          android:versionCode="1"
          android:versionName="1.0">
    <!-- We add an application tag here just so that we can indicate that
         this package needs to link against the android.test library,
         which is needed when building test cases. -->
    <application>
        <uses-library android:name="android.test.runner"/>
    </application>
    <!--
    This declares that this application uses the instrumentation test runner targeting
    the package of nilzor.myapp.  To run the tests use the command:
    "adb shell am instrument -w nilzor.myapp.tests/android.test.InstrumentationTestRunner"
    -->
    <instrumentation android:name="android.test.InstrumentationTestRunner"
                     android:targetPackage="nilzor.myapp"
                     android:label="Tests for nilzor.myapp"/>
</manifest>

和这里是我的测试类:;

And here is my test class:;

package nilzor.myapp.tests;

public class NilzorSomeTest<T extends Activity> extends ActivityUnitTestCase<T>{
    public NilzorSomeTest(Class<T> activityClass){
        super(activityClass);
    }

    @SmallTest
    public void testBlah(){
        assertEquals(1,1);
    }
}

我已经阅读了检测基本面的的activity测试文档,并试图按照此<一个href="http://wptrafficanalyzer.in/blog/android-testing-example-helloworld-with-activityunittestcase/">Hello世界的测试博客,即使它是针对Eclipse。我不能让测试运行,以找到并运行我的测试。我究竟做错了什么?

I have read the testing fundamentals, the activity testing document, and tried following this Hello world test blog, even though it is for Eclipse. I cannot get the test runner to find and run my test. What am I doing wrong?

有些问题,我仍然感到不确定的:

Some of the questions I still feel unsure about are:

  1. 请我需要上面的单元测试方法的注释?
  2. 请我需要preFIX的方法测试,或者是只为JUnit测试?
  3. 在我能测试,子包 nilzor.myapp.tests
  1. Do I need an Annotation above the Unit test method?
  2. Do I need to prefix the method with "test", or is that just for JUnit tests?
  3. Can I have tests in sub-packages of nilzor.myapp.tests?

不过,这个职位的主要问题是为什么不测试运行检测我的测试的?

But the main question of this post is why does not the test runner detect my test?

推荐答案

我刚开始学习有关测试Android应用程序,我一直挣扎着同样的问题。您需要提供默认构造函数的测试类,例如:

I just started learning about testing Android applications and I've been struggling with the same problem. You need to provide default constructor for your test class, for example:

package nilzor.myapp.tests;

public class NilzorSomeTest extends ActivityUnitTestCase<ActivityYouWantToTest>{
    public NilzorSomeTest(){
        super(ActivityYouWantToTest.class);
    }

    @SmallTest
    public void testBlah(){
        assertEquals(1,1);
    }
}

你的其他问题:

about your other questions:

  1. 没有。我的测试仍然没有任何注解运行,但我想这是一个很好的做法,有他们。它允许你指定的测试运行的大小。请参阅<一href="http://stackoverflow.com/questions/4671923/what-is-the-purpose-of-smalltest-mediumtest-and-largetest-annotations-in-an">What是@SmallTest,@MediumTest和@LargeTest标注在了Android的目的是什么?了解详细信息。

是的,你需要测试preFIX。 InteliJ给方法从来没有使用过警告时,有没有测试preFIX和试运行过程中会忽略该方法。

Yes, you need "test" prefix. InteliJ gives "method never used" warning when there's no "test" prefix, and skips that method during test run.

是的。我有我的组织到子包的测试,它似乎运作良好。

Yes. I have my tests organized into subpackages and it seems to be working well.

这篇关于为什么Android的测试运行报告&QUOT;空测试套件&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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