Android 测试项目如何了解主项目中的类?
我试图了解如何在 Android 中应用测试,并按照 Google 网站上的演练进行操作。
我已经通过 IntelliJ 中的向导为应用程序本身创建了一个项目。然后我使用以下内容创建了一个测试项目:
android create test-project -m ../TestableProject -n TestableProjectTests -p TestableProjectTests
我打开了测试项目,并查看了它自动生成的 MyActivityTest
类,但是它似乎无法解析 < code>MyActivity 在主项目中,例如,这不起作用:
import com.example.MyActivity;
我的问题是,测试项目如何才能了解其尝试测试的主应用程序项目中的类?我可以在测试项目的清单中看到以下内容,但这似乎没有多大帮助:
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example"
android:label="Tests for com.example"/>
如何使我的测试项目能够查看我的应用程序项目?
谢谢
I'm trying to understand how testing can be applied in android and have followed this walkthrough on the Google site.
I've created a project for the application itself via the wizard in IntelliJ. Then I've created a test project using the following :
android create test-project -m ../TestableProject -n TestableProjectTests -p TestableProjectTests
I've opened up the test project, and had a look at the MyActivityTest
class it auto generated, however it seems unable to resolve the location of MyActivity
in the main project, for example this doesn't work :
import com.example.MyActivity;
My question is, how can the test project have visibility on classes from the main application project its trying to test? I can see the following in the manifest of the test project but that doesn't seem to help a great deal :
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example"
android:label="Tests for com.example"/>
How can I enable my test project to see my application project?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了对我有用的答案。
由于我使用的是 intelliJ,因此我需要将测试项目作为模块导入到主项目中。它使用相同的项目文件,只是使其作为模块可见,以便项目可以互相看到
记录在此处:http://blogs.jetbrains.com/idea/2010/09/android-unit-testing-support/
Found an answer that worked for me.
Since I'm using intelliJ, I needed to import the test project into the main project as a module. It uses the same project files, just makes it visible as a module so the projects can see each other
Documented here : http://blogs.jetbrains.com/idea/2010/09/android-unit-testing-support/