0

I'm getting color (i.e. R.color.my_white is FFFFFFFF ) from my resource as below

ContextCompat.getColor(getContext(), R.color.my_white)

And when I perform AndroidJUnit4 testing, I also get the same color.

ContextCompat.getColor(getContext(), R.color.my_white)

However their return value differs, where in the actual activity, it is -1, and in the Instrumental Test, it is 520093696. Why is that differing?

(I suspect that the instrumental test context return a different result)

1 Answer 1

0

I found the way to do it. The getContext() in the AndroidJunit4 is not working correctly. So I use

 activityRule.activity.getColor(R.color.my_white)

Where activityRule is

@Rule
@JvmField
var activityRule: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.