I've seen partial answers to similiar issues but never one that actually solved the problem. I've boiled this down to a minimal app to demonstrate the issue.
I'm using the most current version of Android Studio (V2.2.1) I have the following SDK's installed:
Android Support repository v32
Updated build.gradle (app) per: https://developer.android.com/training/testing/start/index.html#config-instrumented-tests
Added under defaultConfig:
Added under dependencies
Did project sync to sync Gradle
Under the "test" package add new test file - ExampleIntegrationTest.java (right next to ExampleUnitTest.java)
In the new file, created integration test per: https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@SmallTest
public interface ExampleIntegrationTest {
}
This is where the problem comes up - cannot resolve symbol AndroidJUnit4 On the line: import android.support.test.runner.AndroidJUnit4;
If I type the import statement I can use the popup suggestions:
- import android. - It shows "support as option"
- import android.support. - It shows "test" as an option
- import android.support.test. - Now it only shows "rule" as a option
After I create the app I make sure it's using the "debug" variant
This is pretty cut and dry. As far as I can tell this should work,, but the support library for some reason isn't getting imported correctly.
Fix this by adding the test to the
Or, when you create the test class, add the test by selecting new class when in "Android Instrumentation Tests" tab of the Project tree
Please ensure you have your tests located at the right folder. There are local and instrumentation tests which must be resided in their respective folders as explained below:
Take a look at this article which says...
Run Instrumented Unit Tests To run your instrumented tests, follow these steps:
Be sure your project is synchronized with Gradle by clicking Sync Project in the toolbar. Run your test in one of the following ways: To run a single test, open the Project window, and then right-click a test and click Run . To test all methods in a class, right-click a class or method in the test file and click Run . To run all tests in a directory, right-click on the directory and select Run tests . The Android Plugin for Gradle compiles the instrumented test code located in the default directory (src/androidTest/java/), builds a test APK and production APK, installs both APKs on the connected device or emulator, and runs the tests. Android Studio then displays the results of the instrumented test execution in the Run window.
Therefore folks, for instrumentation test the folder must be (do not forget the case)
src/androidTest/java
and for local tests the folder must be
src/test/java
You can then have your package folder(s) to match your app package
Hope, this helps for the community!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With