realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

Unit tests should support global init

Open cmelchior opened this issue 9 years ago • 0 comments

Fallout from #3457

Testing this is non-trivial since the Context is now saved in a system-wide Singleton that remains between unit tests.

We need to refactor to allow the following:

  • Add tests for Realm.init() not called
  • Don't require all unit tests to specifically require setting this.

A solution I think will work is:

  1. Introduce a new RealmUnitTestRunner that extends AndroidJUnit4 runner. It will be responsible for calling Realm.init(InstrumentationTarget.getTargetContext())

  2. Add a protected Realm.resetInit() method that allows specific unit tests to reset the state if needed.

cmelchior avatar Sep 19 '16 09:09 cmelchior