src/androidtest和src/test文件夹有什么区别? [英] What's the difference between src/androidtest and src/test folders?

查看:243
本文介绍了src/androidtest和src/test文件夹有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个项目中,默认情况下,在Android Studio中,有两个测试文件夹.

In a project, in Android Studio, by default, there are two test folders.

第一个是src/androidTest.此文件夹在先前版本的Android Studio中已经存在.不过,现在默认情况下有一个新的测试文件夹src/test,而在build.gradle中有一个新的依赖项testCompile 'junit: junit: 4.12'.

The first is src/androidTest. This folder already existed in the previous version of Android Studio. Nevertheless, there is now a new test folder, by default, src/test, and new dependence, testCompile 'junit: junit: 4.12' in build.gradle.

我使用哪个文件夹进行测试?两者之间有什么区别?

Which folder do I use for testing? What are the differences between the two?

推荐答案

src/androidTest适用于涉及Android检测的单元测试.

src/androidTest is for unit tests that involves android instrumentation.

src/test用于不涉及android框架的纯单元测试.您可以在此处运行测试,而无需在真实设备或仿真器上运行.

src/test is for pure unit test that do not involve android framework. You can run tests here without running on a real device or on emulator.

您可以同时使用两个文件夹.使用第一个测试使用Android框架的代码.使用第二个代码测试纯Java类的代码.编写测试的方法几乎相同.

You can use both folders. Use the first one to test code that use Android framework. Use the second one to test code that are pure java classes. The methods to write tests are almost the same.

此处的更多信息: http://developer.android.com/tools/testing/testing_android.html

这篇关于src/androidtest和src/test文件夹有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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