gpt4 book ai didi

java - 在 Android 应用程序中为 Toasts 编写 JUnit 测试

转载 作者:搜寻专家 更新时间:2023-11-01 09:03:50 24 4
gpt4 key购买 nike

我经常使用 Toast.makeText().show() 向我的 Android 应用程序的用户显示消息。这些可以是下一步做什么的说明或错误消息。作为我的 JUnit 测试的一部分,我想包含这些消息在预期时出现的断言。我该怎么做?

最佳答案

我通过使用 Robotium 框架来做到这一点,并在显示 toast 后立即调用它:

     TextView toastTextView = solo.getText(0);
if(toastTextView != null){
String toastText = toastTextView.getText().toString();
assertEquals(toastText, "Your expected text here");
}
//wait for Toast to close
solo.waitForDialogToClose(5000);

关于java - 在 Android 应用程序中为 Toasts 编写 JUnit 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13389361/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com