android difference between testImplementation and androidTestImplementation in build.gradle

后端 未结 2 1692
无人及你
无人及你 2021-02-01 01:17

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 testImplentat

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-01 02:15

    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 : for android UI test. It needs virtual or real device. (Espresso, UI automator)
    • app/src/test : for android independent 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.

    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)

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

    • 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/

提交回复
热议问题