android。build.gradle中testImplementation和androidTestImplementation之间的区别 [英] android difference between testImplementation and androidTestImplementation in build.gradle

查看:275
本文介绍了android。build.gradle中testImplementation和androidTestImplementation之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用andorid studio 3.2,并且是测试的新手。我想添加一个测试库,但是在依赖项 testImplentation androidTestImplementation 中没有得到应写的内容。两者之间有什么区别?

I am using andorid studio 3.2 and I am new to testing. I want to add a testing library but I am not getting what should i write in the dependencies section testImplentation or androidTestImplementation. What is the difference between these two?

推荐答案

如果使用Android Studio创建android项目。
您可以找到以下三个目录。 (每个目录称为 Source Set

If you create android project using Android Studio. You can find three directories like following. (each directory called Source Set)


  • app / src / main

  • app / src / androidTest:用于Android UI测试。它需要虚拟或真实设备。 (Espresso,UI自动化器)

  • app / src / test:用于android独立测试。

androidTest 目录包含触摸屏幕或检查屏幕显示内容的测试用例。
test 目录中,我们主要进行单元测试,例如测试一个功能。

The androidTest directory contains test cases that touch the screen or check what is displayed on the screen. In the test directory, we mainly do unit tests such as testing one function.

但是测试目录不仅用于单元测试。您还可以编写集成测试(如HTTP调用)。
即使您可以使用 Robolectric test 目录中的 UI测试 $ c>库。(它确实比Espresso快得多)

But test directory is not only for Unit test. You can also write Integration test like HTTP call. Even you can UI test in test directory using Robolectric library.(It's really fast rather than Espresso)

那么什么是 testImplementation androidTestImplementation ? (每个称为 Configuration

So what is testImplementation and androidTestImplementation? (each called Configuration)


  • testImplementation:为 test添加依赖c $ c>源集

  • androidTestImplementation:为 androidTest 源集

  • testImplementation : adds dependency for test source set
  • androidTestImplementation : adds dependency for androidTest source set

有关详细信息,请参阅此文章。

See this articles for details.

  • https://developer.android.com/topic/libraries/testing-support-library
  • https://developer.android.com/studio/test/

这篇关于android。build.gradle中testImplementation和androidTestImplementation之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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