NullPointerException on reflection during Robolectric startup - any hints?

后端 未结 3 775
醉梦人生
醉梦人生 2021-01-05 18:28

I am developing an Android project on Eclipse, and I\'m trying to switch from running tests on the emulator/device (which is very slow) to Robolectric.

I re

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-05 18:32

    We have had the same problems in the past. What works for us is extending RoboletricTestRunner and providing it a RoboletricConfig instance that is aware of our Project's location. This way I don't have to tinker with any run configurations with eclipse, it just works.

        package ...;
    
        import java.io.File;
    
        import org.junit.runners.model.InitializationError;
    
        import com.xtremelabs.robolectric.RobolectricConfig;
        import com.xtremelabs.robolectric.RobolectricTestRunner;
    
        public class TestRunner extends RobolectricTestRunner {
    
            public static final string MAIN_PROJECT_PATH = "../path_to_android_project";
    
            public TestRunner(Class testClass) throws InitializationError {
                 super(testClass, new RobolectricConfig(new File(MAIN_PROJECT_PATH)));
            }
        }
    

提交回复
热议问题