Cannot resolve symbol AndroidJUnit4

前端 未结 8 1353
太阳男子
太阳男子 2021-01-18 02:24

I\'m trying to add loginfacebook for my app. But when I added a repository that is need in doing this. It caused an error. The AndroidJUnit4 cannot resolve now.

8条回答
  •  走了就别回头了
    2021-01-18 02:45

    In addition to the above answer please ensure you follow these steps strictly:

    I was banging my head against the wall and/or any object i see in front of me in order to make my SQLite function unit tested. No matter what I do, how strictly follow the suggestions provided my many wise people all over the internet did not work.

    I then had to go to preschool and start over to realize my stupid mistake. I learned that AndroidJUnit4 can only be used with Instrumentation Test and JUnit must be used for local tests. That being said, the folder must be src/androidTest/java. I had my test class directly under androidTest folder, hence I had to face that nasty error. However, the moment I moved it under src/androidTest/java everything went very clear like "I can see clearly now the rain is gone".

    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!

提交回复
热议问题