问题描述
我有一个非常简单的活动,当单击按钮时,它将用户重定向到应用程序的Play商店页面:
I have a very simple activity, that redirects the user to the app's Play Store page, when the button is clicked:
public class MyActivity extends AppCompatActivity {
private static final String PLAY_STORE_URI =
"market://details?id=" + BuildConfig.APPLICATION_ID;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
findViewById(R.id.go_to_play_store).setOnClickListener(this::goToPlayStore);
}
public void goToPlayStore(View view) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(PLAY_STORE_URI));
startActivity(intent);
}
}
是否可以编写测试以检查单击按钮时PlayStore是否已启动?更好,是否可以验证它是否显示了预期的页面?
Is it possible to write a test to check that the PlayStore is launched when the button is clicked? Better, is it possible to verify it shows the expected page?
我知道,通过使用ActivityMonitors,可以测试Activity之间的转换.我也知道我可以验证使用Espresso Intent发送的Intent.但是我真的可以检查用户操作是否启动了另一个应用程序吗?
I know that by using ActivityMonitors transitions between Activities can be tested. I also know that I can verify the Intents being sent using Espresso Intents. But can I actually check that a user action launches another app?
推荐答案
我将单击该按钮,然后使用:
I would click the button, then use:
intended(allOf(
hasAction(Intent.ACTION_VIEW),
hasData("https://play.google.com/store/apps/...your app...")
))
这篇关于测试该应用在Android中启动另一个应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!