I have this layout test, in my layout menu_item_layout.xml
there is an IconTextView
with text "{fa-times}"
. When I try to run the test I get android.view.InflateException
.
But if I remove the text "{fa-times}"
from IconTextView
, the test passed successfully.
MenuItemTest.kt
@RunWith(RobolectricTestRunner::class)
@Config(constants = BuildConfig::class)
class MenuItemLayoutTest {
@Test
fun shouldDisplayCorrectTextViews() {
val layout = RoboLayoutInflater.from(RuntimeEnvironment.application)
.inflate(R.layout.menu_item_layout, MenuItemLayout(RuntimeEnvironment.application, null), true) as MenuItemLayout
assertEquals(layout.itemNameTextView.text,"Item 001")
}
}
menu_item_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp">
<com.joanzapata.iconify.widget.IconButton
android:id="@+id/minusButton"
android:layout_width="60dp"
android:layout_height="60dp"
android:text="{fa-minus-circle}"
android:textColor="@color/minus_button"
android:textSize="24sp"/>
</RelativeLayout>
My assumption is that the RuntimeEnvironment.application
needs to call Iconify.with(FontAwesomeModule())
to load. But I have no clue how to do that. Is it possible to extend RuntimeEnvironment.application
of Robolectric
?
I'm using robolectric:3.1.2
Notes
The test failed when I run ./gradlew test
, but if I run a test on a single file (right clicking the file MenuItemTest.kt
and Run
) it passed.