2017-08-22 53 views
0

我有问题需要在ITALIC风格中测试显示单词。有人可以提供我任何示例代码来显示文字风格吗?我在android studio中使用Espresso和JUnit 4。我非常感谢你的合作。谢谢如何在浓缩咖啡测试中测试单词风格“ITALIC”

+1

使用'机器人:TEXTSTYLE = “斜体”'。 – KeLiuyue

+0

@KeLiuyue ..谢谢。但是如何在Test Automation内部进行测试。 – intan

回答

0

这应该使你的TextView大胆同时强调斜体

的strings.xml

<resources> 
    <string name="register"><u><b><i>Copyright</i></b></u></string> 
</resources> 

要设置该字符串到您的TextView的,在你的main.xml中做到这一点

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/textview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:text="@string/register" /> 

Result

+0

是的。我已经有这个。现在,我想在使用Android Studio的测试自动化中测试ITALIC WORD – intan

0

请尝试以下解。它可能适合你。 核心思想是考虑为您的情况使用自定义的ViewMatcher。

public static Matcher<View> withItalicStyle(final int resourceId) { 
    return new TypeSafeMatcher<View>() { 
     @Override 
     public void describeTo(Description description) { 
      description.appendText("has Italic Text with resource"); 
     } 

     @Override 
     public boolean matchesSafely(View view) { 
      TextView textView = (TextView) view.findViewById(resourceId); 
      return (textView.getTypeface().getStyle() == Typeface.ITALIC); 
     } 
    }; 
} 

而且在你的测试用例,你可以

onView(CustomMatchers.withItalicStyle(R.id.yourResourceId)).check(isDisplayed()); 

对于教程,请古尔样品中https://github.com/googlesamples/android-testing/blob/master/ui/espresso/IdlingResourceSample/app/src/main/java/com/example/android/testing/espresso/IdlingResourceSample/MainActivity.java

+1

您可以避免使用[BoundedMatcher]进行投射(https://developer.android.com/reference/android/support/test/espresso/matcher/BoundedMatcher.html ) –