简体   繁体   English

运行测试时出错,未在AndroidManifest.xml中指定目标包

[英]Error running tests, Target package is not specified in AndroidManifest.xml

I am trying to run unit tests within an Android project within Android Studio. 我正在尝试在Android Studio中的Android项目中运行单元测试。 I have followed this tutorial on how to do so, it seems pretty straightforward. 我已按照本教程的操作方法进行操作,这似乎非常简单。 I have in AndroidManifest.xml declared as so 我在AndroidManifest.xml中声明为

 <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="tests" />

The tag is not inside an Activity, but is inside the 标记不在活动内,但在

When I go to run the tests, I get the error 当我去运行测试时,我得到了错误

Test running failed: Unable to find instrumentation info for: ComponentInfo{com.example/android.test.InstrumentationTestRunner} 测试运行失败:无法找到以下设备的检测信息:ComponentInfo {com.example / android.test.InstrumentationTestRunner}

And that no tests were found. 而且没有发现任何测试。

So far I have only one test class I am trying to run, I believe this is set up correctly 到目前为止,我只尝试运行一个测试类,我相信这是正确设置的

public class ItemTests extends InstrumentationTestCase {

    private Item testItem = new Item("Car");
    public void testGetFoodItemName(){
        assertEquals("Car", testItem.getName());
    }

}

Any help would be fantastic! 任何帮助都太棒了! Thanks! 谢谢!

you can do the following to run tests. 您可以执行以下操作来运行测试。

add the following to build.gradle 将以下内容添加到build.gradle

android { 

    ....

    sourceSets {
        androidTest.setRoot('src/test')
    }

    ....
}

1) make a directory in src with name test as specified above. 1)在src中建立一个目录,其名称为test ,如上所述。

2) further make a directory java inside test . 2)在test里面进一步创建一个目录java You will notice color of java folder is green. 您会注意到java文件夹的颜色是绿色。

3) insider src/test/java/ you can put your ItemTests class and other classes. 3)Insider src/test/java/可以放置ItemTests类和其他类。

4) Right click class ItemTests -> Run ItemTests -> Click ItemTests with android logo to run as android test case. 4)右键单击class ItemTests > Run ItemTests >单击带有android徽标的ItemTests以作为android测试用例运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM