2017-08-22 52 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 ) –