0

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.

wint
  • 1,266
  • 2
  • 14
  • 28
  • @mohammadrezakhalifeh I've added the layout.xml file to the question. – wint Oct 12 '16 at 10:05
  • when the text is empty or any other string like `hello`, it is working fine, But when the text is `{fa-...}` it failed with exception `android.view.InflateException`. I have tried to add the string `{fa-times}` to `string.xml` and it failed as well. – wint Oct 12 '16 at 10:24
  • I'm trying to render external font, FontAwesome, from this library https://github.com/JoanZapata/android-iconify Using any other characters in `IconTextView` works fine. but when it tries to render the font from FontAwesome it is just not working. I think it has something to do with `RoboRuntimeEnvironment.application` – wint Oct 13 '16 at 05:14

0 Answers0