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:'

相关内容

热门资讯

透视免费!wpk辅助购买,hh... 透视免费!wpk辅助购买,hhpoker透视功能如何下载,分享开挂内幕(有挂方法)1、实时hhpok...
透视神器!德普之星app安卓版... 透视神器!德普之星app安卓版破解版,德普之星有辅助软件吗,系统教程(往昔是有挂),支持语音通讯、好...
透视透视!wepoker透视脚... 一、wepoker透视脚本下载简介了解软件请加微:136704302wepoker透视脚本下载是一款...
透视好牌!wepoker透视脚... 透视好牌!wepoker透视脚本安卓,aapoker免费透视脚本,曝光教程(起初真的有挂)是一款可以...
透视软件!wpk辅助购买,德普... 透视软件!wpk辅助购买,德普之星辅助器app,信息共享(有挂透明)1、超多福利:超高返利,海量正版...
透视辅助!wepoker透视脚... 透视辅助!wepoker透视脚本下载,wepoker辅助分析器,攻略方法(果然存在有挂);1分钟了解...
透视挂透视!wepoker底牌... 透视挂透视!wepoker底牌透视脚本下载,德普之星辅助正版,我来向大家传授(有挂透明);是一款可以...
透视挂!aapoker透视怎么... 透视挂!aapoker透视怎么用,wepoker公共底牌,必赢教程(原本是真的有挂);值得一提的是,...
透视透视挂!wepoker免费... 透视透视挂!wepoker免费透视脚本,aapoker可以开挂吗,分享实测(有挂教学);小薇(透视辅...
透视透视!wpk辅助软件,约局... 透视透视!wpk辅助软件,约局吧辅助器,2025版教程(一贯真的是有挂)1、完成wpk辅助软件的残局...