I'm implementing functionality for screenshot testing for my application where I take a screenshot within JUnit test by writing the bitmap of the root view to a file in the emulator file system. I'm looking to save that screenshot file to the host file system where my repository exists; however, the screenshot is saved on the emulator's file system. Furthermore, in the current set of settings that are enabled, the emulator restarts after each test is run, so it looses the screenshot after a test is run.
Using Kotlin code in my JUnit test cases, I was wondering if anybody would be knowledgeable on how to send files that are in the emulator to the host file system programmatically in the emulator run-time. I'm unsure if this is possible; however, any guidance on approaching this issue would be greatly appreciated. Thank you!
I've tried sending files after the test cases are run; however, all screenshots except those that are made in the final test case are lost due to the emulator restarting after each test case runs, despite my expectation that they would persist.
Just figured it out, using the TestStorage
API from androidx.test.services
allows for files to be maintained throughout the state of the application by saving them into a specific folder that does not reset after each test.