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。
あなたはまだエラーを取得してください役立つことを願っています代わりに文字列?ギリシャ文字のサポートに問題がある可能性があります。 – npace
あなたは 'tool_lay'レイアウトを提供できますか?私はあなたの 'ツールバー'レイアウトがどのように見えるかを見たいと思います。おかげさまで – piotrek1543