Reputation: 3686
We're trying to write instrumentationTest for our app.
For example I want to write test for authorization/registration.
However before every test I want to be unauthorized? so I need to clean all data, delete db, etc.
So is there any way to delete app or app's data before every test?
Upvotes: 4
Views: 4943
Reputation: 972
Using Android studio, you can create a test configuration that first uninstalls your app before running a test.
uninstall name.of.your.package
You can test that this new tool works by clicking Tools
-> External Tools
-> "Uninstall myApp" (Or for older Android Studio versions, Tools->Custom Tools->"Uninstall myApp").
Now, when you run this configuration, your app should be uninstalled first, before your tests are run.
Newer Android Studio version's have "Store as project file" option (in their "Edit Configurations..." dialog).
But that only saves tool's build-step (second step of above), and to to share "External Tools" itself through repository, see: Share or Export External tools without using jar-file
Upvotes: 13
Reputation: 375
This question was asked in '13. We have come a long way since then. Android has jUnit test runner that comes with a cleanup mechanism under test orchestrator.
Check it out here https://developer.android.com/training/testing/junit-runner
Upvotes: 3
Reputation: 2178
Use Annotations eg:
@BeforeEach
and put your clean up code there.
Upvotes: 2