Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Robolectric tests failing when used on Robolectric4/Androidx #495

Open
alixwar opened this issue Dec 21, 2018 · 0 comments
Open

Robolectric tests failing when used on Robolectric4/Androidx #495

alixwar opened this issue Dec 21, 2018 · 0 comments

Comments

@alixwar
Copy link

alixwar commented Dec 21, 2018

Problem:
When my Robolectric test executes the following line it crashes (it doesn't crash on the actual device).
Note: I have gotten rid of any usages of LinearLayout as suggested here: https://stackoverflow.com/a/11493550/1859486

StickyListHeadersListView.setAdapter(adapter);

My setup
Plugins:

classpath 'com.android.tools.build:gradle:3.2.1'

Dependences:

implementation 'se.emilsjolander:stickylistheaders:2.7.0@aar'

Test dependencies:

testImplementation('org.robolectric:robolectric:4.1') {
        exclude group: 'org.bouncycastle', module: 'bcprov-jdk15on'
        exclude group: 'androidx.test', module: 'monitor'
    }

Stacktrace:

java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

	at android.widget.ListView.clearRecycledState(ListView.java:532)
	at android.widget.ListView.resetList(ListView.java:519)
	at android.widget.ListView.setAdapter(ListView.java:462)
	at se.emilsjolander.stickylistheaders.StickyListHeadersListView.setAdapter(StickyListHeadersListView.java:722)

Update
I've traced the root cause and isolated it to this line:

        listView.addFooterView(inflater.inflate(R.layout.list_footer, container, false));

Interestingly enough, it only causes failures when running @config(sdk = Build.VERSION_CODES.KITKAT) or @config(sdk = Build.VERSION_CODES.O). It works fine on @config(sdk = Build.VERSION_CODES.P)

list_footer.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom"
        >

    <Space
            android:layout_width="match_parent"
            android:layout_height="@dimen/activity_vertical_margin_large"
            />

</LinearLayout>
@alixwar alixwar changed the title Robolectric tests failing when used on Androidx Robolectric tests failing when used on Robolectric4/Androidx Dec 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant