androidx test: SnackBar error inflate design_layout_snackbar_include.xml

590 views
Skip to first unread message

Leon Lei

unread,
Oct 15, 2019, 12:19:14 PM10/15/19
to Robolectric
Hi Guys

I had try to write androidx unit test with robolectric + espresso + fragment testing, but it crashed at

The layout inflated is design_layout_snackbar_include.xml, so I checked the unit test apk, but the layout file was there.

Then I check the crash stack more carefully, and I have found actually it fail at try to resolve R.color.colorAccent.

I dont know how to solve this problem, did this related about SnackBar or android legacy support library issue, or something else?

Very appreciate if someone can help me with this issue.

BRs

Leon Lei

unread,
Oct 16, 2019, 2:24:50 AM10/16/19
to robol...@googlegroups.com
dependencies
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation "com.google.android.material:material:1.0.0"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

implementation 'androidx.navigation:navigation-fragment-ktx:2.1.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.1.0'

debugImplementation 'androidx.fragment:fragment-testing:1.1.0'

testImplementation 'junit:junit:4.12'
testImplementation 'androidx.test:runner:1.2.0'
testImplementation 'androidx.test.ext:truth:1.2.0'
testImplementation 'androidx.test.ext:junit-ktx:1.1.1'
testImplementation 'androidx.test.ext:truth:1.2.0'
testImplementation 'org.robolectric:robolectric:4.3'
testImplementation 'androidx.test.espresso:espresso-core:3.2.0'
testImplementation 'org.mockito:mockito-core:3.0.0'

androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
My Single test
@RunWith(AndroidJUnit4::class)
@TextLayoutMode(TextLayoutMode.Mode.REALISTIC)
@LooperMode(LooperMode.Mode.PAUSED)
@MediumTest
class CreateTuDouFragmentTest {

@Test
fun saveTuDouTask() {
// GIVEN - launch create tudou fragment
FragmentScenario.launchInContainer(CreateTuDouFragment::class.java).apply {
onFragment {
Navigation.setViewNavController(it.view!!, mock(NavController::class.java))
}
}

// WHEN - user input valid information and save
onView(withId(R.id.tudou_name)).perform(replaceText("title"), closeSoftKeyboard())
onView(withId(R.id.tudou_content)).perform(replaceText("content"), closeSoftKeyboard())
onView(withId(R.id.done_input)).perform(click())

// THEN - we can retrieve task from repo
onSnackBar("Saved").check(matches(isDisplayed()))
}
}
When click done_input, 
viewModel.snarkBarText.observe(this, Observer { msg ->
view?.let {
Snackbar.make(it, msg, Snackbar.LENGTH_SHORT).show()
println("saved")
}
})
Crash stack

Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 5: TypedValue{t=0x2/d=0x7f03008a a=-1}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:546)
at android.widget.TextView.readTextAppearance(TextView.java:3542)
at android.widget.TextView.__constructor__(TextView.java:959)
at android.widget.TextView.<init>(TextView.java)
at android.widget.Button.<init>(Button.java)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.google.android.material.snackbar.Snackbar.make(Snackbar.java:188)


--
You received this message because you are subscribed to the Google Groups "Robolectric" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robolectric...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/robolectric/2d5988ec-0b4f-41a4-88d0-9758d5decbb6%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages