我在这里撞墙,试图弄清楚IntelliJ / Android为什么报告“空测试套件”。我有一个带有两个IntelliJ模块的小项目(Eclipse中的“项目”)。单元测试模块有自己的AndroidManifest.xml,我已将其粘贴在底部。我正在尝试运行ActivityUnitTestCase
,因为测试将取决于Context
-object。
主模块的软件包名称为nilzor.myapp
。测试模块的名称为nilzor.myapp.tests
为什么测试运行程序没有将testBlah()
-方法检测为测试?
<?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>
这是我的测试课:
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);
}
}
我已经阅读了测试基础知识,活动测试文档,并尝试关注这个Hello world测试博客,即使它是针对Eclipse的。我无法让测试跑步者找到并运行我的测试。我究竟做错了什么?
我仍然不确定的一些问题是:
- 在单元测试方法上方是否需要注释?
- 我是否需要为该方法添加“ test”前缀,还是仅用于JUnit测试?
- 我可以在的子包装中进行测试
nilzor.myapp.tests
吗?
但是这篇文章的主要问题是为什么跑步者不能检测到我的考试?
@Test
标记放在测试之上。
cmd+shift+t
快捷方式,该快捷方式将在与您当前正在编辑的类相匹配的正确包位置中自动创建测试类。