Der Einfachheit halber schlage ich ein vollständiges Beispiel:
Produktionscode:
register_terms.text = Html.fromHtml(getString(R.string.register_terms,
getString(R.string.privacy_policy_url),
getString(R.string.register_terms_privacy_policy),
getString(R.string.general_terms_and_conditions_url),
getString(R.string.register_terms_general_terms_and_conditions)))
Strings XML:
<string name="register_terms">By registering you accept our <a href=\"%1$s\">%2$s</a> and the <a href=\"%3$s\">%4$s</a>.</string>
<string name="register_terms_privacy_policy">Privacy Policy</string>
<string name="register_terms_general_terms_and_conditions">General Terms and Conditions</string>
<string name="privacy_policy_url" translatable="false">https://www.privacypolicy.com</string>
<string name="general_terms_and_conditions_url" translatable="false">https://www.generraltermsandconditions.com</string>
Testcode:
@Before
fun setUp() {
Intents.init()
}
@After
fun tearDown() {
Intents.release()
}
@Test
fun when_clickPrivacyLink_then_openPrivacyUrl() {
val expected = allOf(IntentMatchers.hasAction(Intent.ACTION_VIEW), IntentMatchers.hasData(string(privacy_policy_url)))
Intents.intending(expected).respondWith(Instrumentation.ActivityResult(0, null))
onView(ViewMatchers.withId(R.id.register_terms))
.perform(openLinkWithText(string(register_terms_privacy_policy)))
Intents.intended(expected)
}
Siehe Wahibs Antwort unten. – Jamey