2016-08-30 19 views
1

1つのアクティビティに2つのフラグメントが添付されており、そのアクティビティのツールバータイトルをテストします。エスプレッソでツールバーのタイトルテキストをテストする - Android

だから私はこれを書いた:

@Test 
public void testToolbar(){ 
    onView(allOf(instanceOf(TextView.class),withParent(withId(R.id.toolbar)))) 
      .check(matches(withText("Είσοδος/Εγγραφή"))); 

} 

しかし、私はwithTextメソッドに入れたテキストが認識されません。

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with text: is "Είσοδος/Εγγραφή"' doesn't match the selected view. 
Expected: with text: is "Είσοδος/Εγγραφή" 

ここは自分のアクティビティのコードです。

public class MainActivity extends AppCompatActivity { 
public static final String LOGIN_FRAGMENT = "LOGIN_FRAGMENT"; 
public static final String REGISTER_FRAGMENT = "REGISTER_FRAGMENT"; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_main); 
    setTitle("Eίσοδος/Εγγραφή"); 

    LoginFragment loginFragment = new LoginFragment(); 
    FragmentManager fragmentManager = getSupportFragmentManager(); 
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
    fragmentTransaction.add(android.R.id.content,loginFragment,LOGIN_FRAGMENT); 
    fragmentTransaction.commit(); 
} 

public void userReg(View view){ 
    RegisterFragment regFragment = new RegisterFragment(); 
    FragmentManager fragmentManager1 = getSupportFragmentManager(); 
    FragmentTransaction fragmentTransaction1 = fragmentManager1.beginTransaction(); 
    fragmentTransaction1.addToBackStack("added"); 
    fragmentTransaction1.replace(android.R.id.content,regFragment,REGISTER_FRAGMENT); 
    fragmentTransaction1.commit(); 
    } 
} 

と対応するxmlファイルです。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="team.football.ael.MainActivity" 
> 
<include 
    android:id="@+id/toolbar" 
    layout="@layout/tool_lay" 
    /> 
</RelativeLayout> 

これは何が起こっているのですか?すべてがそこにあります。

ありがとう、 Theo。

+0

あなたはまだエラーを取得してください役立つことを願っています代わりに文字列?ギリシャ文字のサポートに問題がある可能性があります。 – npace

+0

あなたは 'tool_lay'レイアウトを提供できますか?私はあなたの 'ツールバー'レイアウトがどのように見えるかを見たいと思います。おかげさまで – piotrek1543

答えて

2

私はあなたのtool_layoutはこのようになっていることを前提としています。ここ

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="?colorPrimary" 
    android:minHeight="?actionBarSize" 
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:navigationContentDescription="@string/abc_action_bar_up_description" 
    app:navigationIcon="?homeAsUpIndicator" 
    app:title=""> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="@string/app_name"/> 
</android.support.v7.widget.Toolbar> 

はテストです:

onView(withId(R.id.toolbar)).check(matches(isDisplayed())); 
    onView(withText(R.string.app_name)).check(matches(withParent(withId(R.id.toolbar)))); 

が、それはあなたが英語を使用する場合

+0

乳は固定されています。 – Theo

関連する問題