Nil*_*zor 98 android intellij-idea
我正在试图找出IntelliJ/Android报告"空测试套件"的原因.我有一个带有两个IntelliJ模块的小项目(Eclipse中的"Projects").Unit测试模块有自己的AndroidManifest.xml,我在底部粘贴了它.我试图运行ActivityUnitTestCase,因为测试将取决于对象Context.
主模块的包名称是nilzor.myapp.测试模块的pacakge名称是nilzor.myapp.tests
为什么测试运行器没有检测到testBlah()-method作为测试?
<?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>
Run Code Online (Sandbox Code Playgroud)
这是我的测试课:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
我已经阅读了测试基础知识,活动测试文档,并尝试了这个Hello world测试博客,尽管它适用于Eclipse.我无法让测试运行员找到并运行我的测试.我究竟做错了什么?
我仍然不确定的一些问题是:
nilzor.myapp.tests吗?但是这篇文章的主要问题是为什么测试运行器没有检测到我的测试?
小智 70
您需要为测试类提供默认构造函数,例如:
package nilzor.myapp.tests;
public class NilzorSomeTest extends ActivityUnitTestCase<ActivityYouWantToTest>{
public NilzorSomeTest(){
super(ActivityYouWantToTest.class);
}
@SmallTest
public void testBlah(){
assertEquals(1,1);
}
}
Run Code Online (Sandbox Code Playgroud)
关于你的其他问题:
不.我的测试仍然没有任何注释,但我想这是一个很好的做法.它允许您指定要运行的测试的大小.请参阅Android中@SmallTest,@ MediumTest和@LargeTest注释的目的是什么?了解更多细节.
是的,你需要"测试"前缀.当没有"test"前缀时,InteliJ给出"方法从未使用"警告,并在测试运行期间跳过该方法.
是.我将我的测试组织成子包,它似乎运行良好.
tir*_*r38 54
如果这种情况"突然发生"或"它在5分钟前工作"我的解决方案是进入运行/调试配置并删除"Android测试"下的任何配置.如果我重构被测试的类(例如,移动到新的包),有时这些配置会被破坏.
| 归档时间: |
|
| 查看次数: |
66094 次 |
| 最近记录: |