Android-espresso(Kotlin):使用writeToTestStorage方法保存位图
创始人
2024-08-19 18:00:10
0

在espresso测试中使用writeToTestStorage方法保存位图可以非常有用。这可以让我们将测试结果保存到设备的本地存储中以备后续使用。以下是使用Kotlin编写的示例代码:

@Test
fun testSaveBitmapToTestStorage() {
    // Get a reference to the bitmap you want to save
    val bitmap = BitmapFactory.decodeResource(
        InstrumentationRegistry.getInstrumentation().context.resources,
        R.drawable.test_bitmap
    )

    // Specify the file name and path
    val fileName = "test_bitmap.png"
    val directory = InstrumentationRegistry.getInstrumentation().targetContext.filesDir

    // Save the bitmap to file using writeToTestStorage method
    writeToTestStorage(bitmap, fileName, directory)

    // Verify that the file exists in the specified directory
    val file = File(directory.toString() + "/" + fileName)
    assertTrue(file.exists())
}

该测试用例获取一个位图引用,指定文件名和路径,使用writeToTestStorage方法将位图写入本地存储,并验证该文件是否存在。使用以下导入语句导入writeToTestStorage方法:

import androidx.test.runner.screenshot.WriteToTestStorage.writeToTestStorage

这需要在build.gradle文件中添加以下依赖项:

androidTestImplementation 'androidx.test.espresso:espresso-core:'

相关内容

热门资讯

透视安卓版!hhpoker有辅... 透视安卓版!hhpoker有辅助的吗,wepoker有辅助工具吗,积累教程(切实是有挂)-哔哩哔哩1...
透视总结!wpk真的有透视嘛(... 透视总结!wpk真的有透视嘛(透视)开挂辅助app(竟然真的有挂)-哔哩哔哩1、这是跨平台的wpk真...
透视ai代打!aapoker ... 透视ai代打!aapoker ai插件,pokernow辅助工具,指南书教程(都是有挂)-哔哩哔哩1...
透视辅助器!we poker游... 透视辅助器!we poker游戏下(透视)开挂辅助app(总是真的是有挂)-哔哩哔哩1、进入游戏-大...
透视免费!wepoker辅助器... 透视免费!wepoker辅助器软件下载,we poker辅助器v3.3,绝活教程(原来是有挂)-哔哩...
透视苹果版!hhpoker怎么... 透视苹果版!hhpoker怎么开透视(透视)开挂辅助攻略(果然是真的挂)-哔哩哔哩1、打开软件启动之...
透视安装!淘宝买wepoker... 透视安装!淘宝买wepoker透视有用吗,hhpoker为什么一直输,妙计教程(其实真的是有挂)-哔...
透视科技!wpk安卓下载辅助(... 透视科技!wpk安卓下载辅助(透视)开挂辅助攻略(真是真的是有挂)-哔哩哔哩一、wpk安卓下载辅助软...
透视数据!德普之星怎么开辅助,... 透视数据!德普之星怎么开辅助,wepoker智能辅助插件,模块教程(原来是有挂)-哔哩哔哩;1、下载...
透视代打!hhpoker为什么... 透视代打!hhpoker为什么一直输(透视)开挂辅助攻略(一贯有挂)-哔哩哔哩1、下载好hhpoke...