I am migrating my app to androidx, I can\'t seem to get my unit tests working. I took example from Google\'s AndroidJunitRunnerSample, which has been updated to use the new
In my case, I fixed it by explicitly declaring all @Test, @Before, and @After methods aspublic, and declaring @BeforeClass and @AfterClass as public static
If you leave any of those methods as implicitly/explicitly protected, or explicitly private; you'll encounter the following exception
java.lang.RuntimeException: Delegate runner 'androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner' for AndroidJUnit4 could not be loaded.
So, the correct thing is to use
@Before
public void setUp() {
}
@BeforeClass
public static void init() {
}
Instead of:
@Before
void setUp() {
}
@Before
protected void setUp() {
}
@Before
private void setUp() {
}
@BeforeClass
public void init() {
}