robolectric / robolectric

Android Unit Testing Framework
http://robolectric.org
Other
5.87k stars 1.36k forks source link

class org.robolectric.res.ResourceTableFactory cannot access a member of class android.R$styleable #8532

Closed TJJ123456 closed 10 months ago

TJJ123456 commented 11 months ago

Description

When I run test with Coverage in android studio encounter the exception

java.lang.IllegalAccessException: class org.robolectric.res.ResourceTableFactory cannot access a member of class android.R$styleable with modifiers "private static transient"
But I run with Jacoco is ok, Is there any way I can make "run with xxxTest with Coverage" successful.

Steps to Reproduce

My code

public class Calculator {
    public int add(int a, int b) {
        return a + b;
    }
}

My test code

@RunWith(RobolectricTestRunner.class)
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "android.*", "org.json.*", "sun.security.*", "javax.net.*"})
public class CalculatorTest {
    @InjectMocks
    private Calculator calculator;

    @Test
    public void should_correct_when_add_given_sample() {
        Assert.assertEquals(3, calculator.add(1,2));
    }
}

Robolectric & Android Version

Robolectric version: 4.7.3 JDK version: 1.8 Android version: 33

learner1999 commented 11 months ago

I also encountered the same problem……

hoisie commented 10 months ago

1) Robolectric 4.7.3 is many years old at this point, please update to 4.12-SNAPSHOT and see if the issue is still there.

2) Mockito-inline is the only officially supported agent-based mocking framework for Robolectric. If you are using others (e.g. PowerMock, Mockk), they may be interfering with the instrumentation Robolectric does on Android classes, and fixing these issues requires in-depth knowledge of the instrumentation that is performed by Powermock. Unfortunately we do not have the time and resources to debug these issues. However, if you'd like to take a deep dive and see what's going on, we'd be happy to provide support for any questions related to Robolectric-based instrumentation.

hoisie commented 10 months ago

Closing since there is no sample app or clear repro instructions using 4.12-SNAPSHOT.