ChatGPT解决这个技术问题 Extra ChatGPT

What's the difference between src/androidtest and src/test folders?

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

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?


B
Bipi

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

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.

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.

More info here : http://developer.android.com/tools/testing/testing_android.html


You just saved my day
what about androidTestDebug?
C
Community

Great source of information relating to android testing in general is developers page Best Practices for Testing:

Local unit tests (/src/test/java/) Unit tests that run locally on the Java Virtual Machine (JVM). Use these tests to minimize execution time when your tests have no Android framework dependencies or when you can mock the Android framework dependencies. Instrumented tests (/src/androidTest/java/) Unit tests that run on an Android device or emulator. These tests have access to Instrumentation information, such as the Context of the app you are testing. Use these tests when your tests have Android dependencies that mock objects cannot satisfy.

https://i.stack.imgur.com/qUnwh.png


a
akhilesh0707

A typical project in Android Studio contains two directories in which you place tests.

1. Instrumented testing (/src/androidTest/java/)

The androidTest directory should contain the tests that run on real or virtual devices. Such tests include integration tests, end-to-end tests, and other tests where the JVM alone cannot validate your app's functionality.

With instrumented testing, we are able to verify app logic that needs a real device, so mostly we will verify the UI. We will also use JUnit and we will add Espresso.

2. Unit testing (/src/test/java/)

The test directory should contain the tests that run on your local machine, such as unit tests.

Unit tests are used to verify that business logic is working right without using a real device.e. We will use JUnit, hamcrest, and mockito-kotlin to achieve this.

https://i.stack.imgur.com/Ko1RN.jpg

More info read this article


y
yoAlex5

Android test src folders test vs androidtest

src/test - Unit Tests

src/androidtest - Android Instrumentation tests

[Read more]