Roboletric 4.8.2 修改进程名:
| 
					 1 2 3  | 
						import org.robolectric.shadows.ShadowApplication; ShadowApplication.setProcessName();  | 
					
Roboletric 4.8.2 修改私有静态变量:
| 
					 1 2 3  | 
						import org.robolectric.util.ReflectionHelpers; ReflectionHelpers.setStaticField(xx.class, "static filed name", value);  | 
					
如果报错:
| 
					 1 2 3 4  | 
						java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation. 	at androidx.test.platform.app.InstrumentationRegistry.getInstrumentation(InstrumentationRegistry.java:45) 	at androidx.test.core.app.ApplicationProvider.getApplicationContext(ApplicationProvider.java:41)  | 
					
则修改方式如下:
| 
					 1  | 
						@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "android.*", "androidx.*"})  | 
					
完整的例子如下:
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  | 
						    import org.junit.runner.RunWith;     import org.powermock.core.classloader.annotations.PowerMockIgnore;     import org.powermock.modules.junit4.PowerMockRunner;     import org.powermock.modules.junit4.PowerMockRunnerDelegate;     import org.robolectric.RobolectricTestRunner;     import org.robolectric.annotation.Config;     /**      * Base class extended by every Robolectric test in this project.      * <p/>      * You can use Powermock together with Robolectric.      */     @RunWith(PowerMockRunner.class)     @PowerMockRunnerDelegate(RobolectricTestRunner.class)     @Config(constants = BuildConfig.class,             sdk = 21)     @PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "android.*", "androidx.*"})     public abstract class RobolectricTest {     }  | 
					





 
 

 
 
 

