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

相关内容

热门资讯

透视辅助!pokemmo内置修... 透视辅助!pokemmo内置修改器(透视)揭秘攻略(2024已更新)(哔哩哔哩)1、pokemmo内...
透视玄学!aapoker辅助软... 透视玄学!aapoker辅助软件合法吗(透视)免费透视脚本(一贯真的是有挂)1、让任何用户在无需aa...
透视规律!werplan辅助软... 透视规律!werplan辅助软件(透视)必赢方法(2022已更新)(哔哩哔哩)该软件可以轻松地帮助玩...
透视攻略!aapoker辅助怎... 透视攻略!aapoker辅助怎么用(透视)透视脚本下载(都是是真的有挂)1、进入到aapoker辅助...
透视脚本!werplan怎么作... 透视脚本!werplan怎么作弊(透视)扑克教程(2024已更新)(哔哩哔哩)1、下载好werpla...
透视安装!aapoker怎么拿... 透视安装!aapoker怎么拿好牌(透视)ai插件(原来有挂)1、游戏颠覆性的策略玩法,独创攻略技巧...
透视能赢!约局吧德州有挂吗(透... 透视能赢!约局吧德州有挂吗(透视)存在挂教程(2021已更新)(哔哩哔哩)1、全新机制【约局吧德州有...
透视系统!智星德州辅助译码插件... 透视系统!智星德州辅助译码插件靠谱吗(透视)wepoke教程(2021已更新)(哔哩哔哩)智星德州辅...
透视数据!aapoker脚本(... 透视数据!aapoker脚本(透视)脚本(确实是有挂)1、让任何用户在无需aapoker脚本AI插件...
透视苹果版!约局吧辅助器(透视... 透视苹果版!约局吧辅助器(透视)玩家教你(2026已更新)(哔哩哔哩)亲,关键说明,约局吧辅助器赛季...