Reset singleton field during JUnit tests, roboelectric junit tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@After | |
public void teaddown() { | |
setting.clear(); | |
resetSingleton(ErgoSettings.class, "sInstance"); | |
} | |
public static void resetSingleton(Class clazz, String fieldName) { | |
Field instance; | |
try { | |
instance = clazz.getDeclaredField(fieldName); | |
instance.setAccessible(true); | |
instance.set(null, null); | |
} catch (Exception e) { | |
throw new RuntimeException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment