Last active
February 4, 2019 10:11
-
-
Save iRYO400/d2b5517851f9f3a4373d91f1e18f5de8 to your computer and use it in GitHub Desktop.
#robolectric #robolectric4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Backgrounds of views | |
Drawable currentDrawable = textView.getBackground(); | |
Drawable expectedDrawable = getApplicationContext().getDrawable(R.drawable.background_item_chip_yellow); | |
assertThat(shadowOf(currentDrawable).getCreatedFromResId()).isEqualTo(shadowOf(expectedDrawable).getCreatedFromResId()); | |
// Colors of TextView | |
int expectedColor = ContextCompat.getColor(getApplicationContext(), R.color.text_blue); | |
assertThat(textView.getCurrentTextColor()).isEqualTo(expectedColor); | |
// Colors of Drawable backgrounds | |
Drawable drawable = view.getBackground(); | |
int currentColor = ((ColorDrawable) drawable).getColor(); | |
int expectedColor = ContextCompat.getColor(getApplicationContext(), R.color.report_blue); | |
assertThat(currentColor).isEqualTo(expectedColor); | |
// ImageView#setImageResource(int id) - imageView.setImageResource(iconResId); | |
Drawable expected = getApplicationContext().getDrawable(R.drawable.ic_plus_blue); | |
assertThat(shadowOf(imageView.getDrawable()).getCreatedFromResId()).isEqualTo(shadowOf(expected).getCreatedFromResId()); | |
// In case if you get exception when initializing view | |
// java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a descendant). | |
// Check this https://stackoverflow.com/questions/32346748/robolectric-illegalstateexception-you-need-to-use-a-theme-appcompat-theme-or |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment