Migrating Junit4 tests to androidx: What causes 'delegate runner could not be loaded'?

后端 未结 19 1814
长情又很酷
长情又很酷 2020-12-05 06:35

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

19条回答
  •  渐次进展
    2020-12-05 06:53

    You need to make sure that any class marked with the @BeforeClass annotation is public static . For example:

    import org.junit.BeforeClass;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    
    import androidx.test.ext.junit.runners.AndroidJUnit4;
    
    @RunWith(AndroidJUnit4.class)
    public class EntityParcelTest {
    
        @BeforeClass
        public static void createEntities() {
            // Setup...
        }
    
        @Test
        public void someTest() {
            // Testing here
        }
    

提交回复
热议问题