AndroidStudio中用测试做单元测试

AndroidStudio里,做单元测试也可以的,如果是很旧版本的as需要手动去导入测试类的类库


testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

如果是新版本的,则不需要导入依赖,
新建的项目,在项目的test包下有ExampleUnitTest这个类(自动生成的,在这个类里面操作)

有@Test注解的方法左边都有一个运行图标,选择run就好了
重点提示:
1.写一个方法在方法上面要写加上@Test注解
2.方法里不能有参数(必须的,要不会报错)
示例书写:

@Test
    public  void hi() {
        System.out.println("hia 美男,你好");
    }

如上描述就ok了,如出现问题:加我qq号:1393508286

Guess you like

Origin blog.csdn.net/ShiXinXin_Harbour/article/details/121146946