I am trying to test that my EditText hint field is not null in junit’s
testPreconditions()
There are examples online for asserting that a TextView is not null, but using EditText in the following way
private EditText editTextField;
public void testPreconditions() {
assertNotNull(editTextField);
}
does not work (tests fail).
How do I access the android:hint field of EditText in the assert?
And while this question targets the hint field, answers that also work for similar situations (text of a button, title / elements of a spinner, etc) would be greatly appreciated.
Thanks!
To get hint from
EditTextusegetHintfunction.But it looks like your problem is different. Your test fails because your
editTextFieldis null. You should read “Activity Testing” article. Shortly, JUnit is not enough, you need to setup a special Android Test project in order to access UI views ofActivityunder test.