close
1.gradle 新增依賴
testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.0.2' androidTestImplementation 'androidx.test:rules:1.2.0'
2.取得context
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4ClassRunner.class) public class Test { Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); }
全站熱搜