简体   繁体   中英

Testing UI Robotium

I a little bit new in programming for android, but I need to write UI automation tests. I use Robotium, but even I only invoked code below I have "Test run failed: Instrumentation run failed due to 'java.lang.IllegalAccessError'" I config project with test cases sccording to Robotium tutorial.

public class ExampleTest extends ActivityInstrumentationTestCase2<MapActivity> {

    private Solo mSolo;

    public ExampleTest() {
        super(MapActivity.class);
    }  

    public void setUp() throws Exception {
        super.setUp();
        mSolo = new Solo(getInstrumentation(), getActivity());
    }

    public void testPreferenceIsSaved() throws Exception {

    }

    @Override
    public void tearDown() throws Exception {
        mSolo.finishOpenedActivities();
    }
}

I had that error in LogCat: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation

This is a bit of an annoying error, basically the error you are seeing is because you are compiling in a class to your test apk that exists in your real apk (my guess is probably the application itself but it could be a library you both use).

What happens (not exactly but its a good enough mental model) is that when you launch your tests it puts all of the classes in the same classpath as that of your apps and when it tries to launch an activity the DVM is clever enough to realise that the activity launched is not the one it was expecting.

How to solve this i hear you ask? Well make sure that any dependencies in your test app that exist in your main app are set to provided or whatever the equivalent is so that they are not compiled into the APK.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM