Android Studio 3.0 Beta 5
robolectric:3.3.1
मेरे पास निम्न दृश्य धारक है जो ग्लाइड लाइब्रेरी का उपयोग करके एक छवि यूआरएल लोड करता है। मैं इकाई परीक्षण इस के लिए एक रास्ता खोजने की कोशिश कर रहा हूँ:यूनिट टेस्ट ग्लाइड: सुनिश्चित करें कि छवि दृश्य में सही छवि
public class MovieActorsViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.civActorPicture) CircleImageView actorPicture;
@BindView(R.id.tvName) TextView name;
@BindView(R.id.tvCharacter) TextView character;
private Context context;
public MovieActorsViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
context = itemView.getContext();
}
public void populateActor(Actor actor) {
Glide.with(context)
.load(actor.getPicturePath())
.placeholder(R.drawable.people_placeholder)
.into(actorPicture);
name.setText(actor.getName());
character.setText(actor.getCharacter());
}
}
इस इकाई परीक्षण मैंने किया है है, लेकिन मुझे यकीन है कि नहीं कर रहा हूँ कि कैसे मैं इकाई परीक्षण छवि देख सकते हैं। मुझे यकीन नहीं है कि ग्लाइड लाइब्रेरी का मज़ाक उड़ाए जाने के लिए मॉकिटो का उपयोग करना होगा?
@RunWith(RobolectricTestRunner.class)
public class MovieActorsViewHolderTest {
private MovieActorsViewHolder movieActorsViewHolder;
@Before
public void setup() {
final Context context = ShadowApplication.getInstance().getApplicationContext();
final View view = LayoutInflater.from(context).inflate(R.layout.movie_actors_item, new LinearLayout(context));
movieActorsViewHolder = new MovieActorsViewHolder(view);
}
@Test
public void testShouldPopulateActorWithValidData() {
final Actor actor = getActor();
movieActorsViewHolder.populateActor(actor);
/* test that the image view */
final ShadowDrawable shadowDrawable = Shadows.shadowOf(movieActorsViewHolder.actorPicture.getDrawable());
final Drawable drawable = Drawable.createFromPath(actor.getPicturePath());
assertThat(drawable, is(shadowDrawable.getCreatedFromResId()));
assertThat(movieActorsViewHolder.name.getText(), is(actor.getName()));
assertThat(movieActorsViewHolder.character.getText(), is(actor.getCharacter()));
}
private Actor getActor() {
return new Actor(
"https://image.tmdb.org/t/p/w92/dRLSoufWtc16F5fliK4ECIVs56p.jpg",
"Robert Danny Junior",
"Iron Man");
}
}
आउटपुट:
Expected: is <[email protected]>
but: was <[email protected]>
Expected :is <[email protected]>
Actual :<[email protected]>
किसी भी सुझाव के लिए बहुत धन्यवाद।
क्या यह नेटवर्क से या संसाधनों से चित्र लोड करता है? –