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

相关内容

热门资讯

透视练习!wejoker免费脚... 透视练习!wejoker免费脚本(HHpoker脚本)确实是真的有辅助神器(哔哩哔哩)进入游戏-大厅...
今天上午!微乐小程序黑科技,微... 今天上午!微乐小程序黑科技,微乐小程序破解版修改器(透视)好像是有辅助脚本(哔哩哔哩)在进入软件靠谱...
随着!微信微乐游戏辅助脚本,微... 随着!微信微乐游戏辅助脚本,微乐辅助脚本(透视)真是存在有辅助工具(哔哩哔哩)1、公共底牌简单,透视...
透视办法!aapoker怎么控... 透视办法!aapoker怎么控制牌(WePoKer价格)果然是真的有辅助软件(哔哩哔哩)1、玩家可以...
透视手筋!wepoker能不能... 透视手筋!wepoker能不能透视(德普之星辅助软件)好像真的有辅助神器(哔哩哔哩)1、操作简单,无...
辅助透视!微信微乐游戏辅助脚本... 辅助透视!微信微乐游戏辅助脚本,陕西微乐小程序修改器(透视)一贯是真的辅助挂(哔哩哔哩)1)免费钻石...
透视攻略!wpk是真的还是假的... 透视攻略!wpk是真的还是假的(AApoker底牌)果然真的是有辅助软件(哔哩哔哩)1、每一步都需要...
明白辅助挂!微乐小程序黑科技,... 明白辅助挂!微乐小程序黑科技,微乐自建房辅助工具2025在哪(透视)总是是有辅助软件(哔哩哔哩)1、...
透视手册!wepokerplu... 透视手册!wepokerplus开挂(AApoker透视脚本)竟然是真的有辅助脚本(哔哩哔哩)1)w...
透视好友!微乐小程序黑科技免费... 透视好友!微乐小程序黑科技免费,小程序微乐游戏辅助器(透视)竟然有辅助神器(哔哩哔哩)1、完成有辅助...