|
|
@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
package net.micode.notes;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.test.platform.app.InstrumentationRegistry;
|
|
|
|
|
|
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 仪器化测试类,运行在真实Android设备或模拟器上
|
|
|
|
|
|
|
|
* 用于验证应用的基本配置是否正确
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@RunWith(AndroidJUnit4.class)
|
|
|
|
|
|
|
|
public class ExampleInstrumentedTest {
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 测试应用上下文的包名是否正确
|
|
|
|
|
|
|
|
* 这是一个基本的健全性检查,确保测试环境能够正确加载应用
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void useAppContext() {
|
|
|
|
|
|
|
|
// 获取被测应用的上下文
|
|
|
|
|
|
|
|
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 验证应用包名是否符合预期
|
|
|
|
|
|
|
|
// 包名是应用的唯一标识符,通常在build.gradle文件中定义
|
|
|
|
|
|
|
|
assertEquals("net.micode.notes", appContext.getPackageName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|