facebook / screenshot-tests-for-android

Generate fast deterministic screenshots during Android instrumentation tests
http://facebook.github.io/screenshot-tests-for-android
Apache License 2.0
1.74k stars 229 forks source link

Add pluggable API for test name resolution #268

Open drewhamilton opened 3 years ago

drewhamilton commented 3 years ago

The core module's internals use static functions in TestNameDetector to determine the name of the current test class and test. These functions parse the stacktrace of the current thread to determine these values.

This works fine if you take screenshots from the test thread, but not so well when running them from another thread. Since UI interactions with ActivityScenario occur on the main thread, this is a problem. See Karumi/Shot#135 for more information.

If it's possible to somehow find the test name from the main thread, I suggest that TestNameDetector be updated to do that. But I don't think this is possible. In that case, I would propose the following API additions:

  1. An interface TestNameProvider with abstract getTestClass and getTestName methods
  2. A way to plug in any custom implementation of TestNameProvider for this library to use internally.

The default TestNameProvider implementation could pass through to TestNameDetector so that the default behavior does not change. But any consumer who needs to can instead provide an explicit name for their test.