oppia / oppia-android

A free, online & offline learning platform to make quality education accessible for all.
https://www.oppia.org
Apache License 2.0
315 stars 517 forks source link

Move all tests under app module test to sharedTest #2532

Open BenHenning opened 3 years ago

BenHenning commented 3 years ago

We have local tests under the app module test folder that only run on Robolectric. Now that we have the RunOn annotation, we should prefer keeping all tests under app module's sharedTest folder & instead use the RunOn animation. This issue is tracking:

dipu989 commented 3 years ago

@BenHenning Would like to work upon this! Can I self assign?

rt4914 commented 3 years ago

@BenHenning Would like to work upon this! Can I self assign?

@dipu989 Yes you can self-assign.

dipu989 commented 3 years ago

@rt4914 @BenHenning How I am thinking about going with this issue is - Viewing the Project structure, we have sharedTest and test directories. I have to move the tests from "test" directory to the "sharedTest" directory in their respective counterparts and refactor if needed.

I have few doubts here - 1) I need to add @RunOn(ROBOELECTRIC) annotation in every test.kt file which are already using @RunWith(AndroidJunit4::class). Do these Junit annotations need to be replaced with Roboelectric ones above every class declaration?

2) Can you elaborate a bit more on the point 'Removing the Gradle/Bazel code around the app module test folder'.

BenHenning commented 3 years ago

@dipu989 good questions. I hope this will help clarify:

  1. RunOn and RunWith are independent of one another, so we may need both in some cases (but we always need RunWith)
  2. I looked into this a bit more--it seems that nothing needs to change in Gradle, but our Bazel file will have a bunch of test references that need to be updated once the tests are moved (here is one example)
anandwana001 commented 3 years ago

@dipu989 any update on this?

dipu989 commented 3 years ago

@anandwana001 I might get this done by the beginning of the next week. Sorry for blocking this for quite a long time.

dipu989 commented 3 years ago

@BenHenning @anandwana001 Local tests are passing but the instrumentation ones are giving this error. Any pointers to resolve this? Running on Realme device as well as emulator gives this error.

Screenshot from 2021-02-14 22-39-48

anandwana001 commented 3 years ago

Gradle sync, invalid cache and restart, clean and rebuild project helps here. Take pull from latest develop branch.

dipu989 commented 3 years ago

@anandwana001 Tried with all the steps above and getting same result. Switched to logcat and saw AndroidOrchestration failed error having below errors

e/androidx test orchestrator: fatal exception when setting up

attempt to invoke virtual method 'android.content.context android.app.instrumentation.getcontext()' on a null object reference.

Is it my device related issue?

anandwana001 commented 3 years ago

Have you tried with fresh emulator?

dipu989 commented 3 years ago

Created an emulator and tried running tests. This error comes - (No tests were found). I tried Invalidating cache restart and clean rebuild. Screenshot from 2021-02-17 22-13-40

anandwana001 commented 3 years ago

Did you cloning the repo again?

dipu989 commented 3 years ago

Will try this and check if the tests are working.

FareesHussain commented 3 years ago

@dipu989 Can you try installing the app and then running the Espresso tests.

dipu989 commented 3 years ago

@anandwana001 I tried cloning again and the issue is still there. @FareesHussain I installed the app on my device and tried running tests on it and it failed. I am attaching a gif for reference - oppia

Tried turning off the animations as well but didn't help.

FareesHussain commented 3 years ago

@dipu989 I'm not sure how to fix this. Can you try running any other Espresso tests?

dipu989 commented 3 years ago

@FareesHussain Same issue with other tests. Do we have to enable/disable any feature in developer mode for these Espresso tests to run?

FareesHussain commented 3 years ago

@FareesHussain Same issue with other tests. Do we have to enable/disable any feature in developer mode for these Espresso tests to run?

No, there is no such option.

dipu989 commented 3 years ago

@FareesHussain @anandwana001 Tried a workaround from StackOverflow where it was suggested to create an emulator with API less than equal to 28. Did the same and espresso tests are now running successfully. It was not running on an emulator with API level 30 but worked on 28. So should I run the tests after refactor on the new emulator (API 28) itself?

FareesHussain commented 3 years ago

@FareesHussain @anandwana001 Tried a workaround from StackOverflow where it was suggested to create an emulator with API less than equal to 28. Did the same and espresso tests are now running successfully. It was not running on an emulator with API level 30 but worked on 28. So should I run the tests after refactor on the new emulator (API 28) itself?

That's great. I haven't tested running the app or Espresso on API 30. But it is not recommended to use API 30 as the targetSdkVersion is 29 and this might be causing the issue here. https://github.com/oppia/oppia-android/blob/0213cdf50c3abcd39ef588fb5560242e391f0ecc/app/build.gradle#L14