3

I am trying to write a sample test for notepad application. In the following code , I get a warning and I'm unable to run the test. Please help me resolve this. The warning says "The constructor ActivityInstrumentationTestCase2<NotesList>(String, Class<NotesList>) is deprecated" and execution in Eclipse stops at testAddNote();. Please revert back in case u need any logcat logs.

package com.example.android.notepad.test;
import com.example.android.notepad.*;
import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.*;

public class NotePadTest extends ActivityInstrumentationTestCase2<NotesList> {
    private Solo solo;
    public NotePadTest() {
        super("com.example.android.notepad", NotesList.class);
    }   
    @Override
    public void setUp() throws Exception {
        solo = new Solo(getInstrumentation(), getActivity());
    }
    @Smoke
    public void testAddNote() throws Exception {
        solo.clickOnButton(0);
        //Assert that NoteEditor activity is opened
        solo.assertCurrentActivity("Expected NoteEditor activity", "NoteEditor"); 
        //In text field 0, add Note 1
        solo.enterText(0, "Note 1");
        solo.goBack(); 
        //Clicks on menu item
        solo.clickOnMenuItem("Add note");
        //In text field 0, add Note 2
        solo.enterText(0, "Note 2");
        //Go back to first activity named "NotesList"
        solo.goBackToActivity("NotesList"); 
        boolean expected = true;
        boolean actual = solo.searchText("Note 1") && solo.searchText("Note 2");
        //Assert that Note 1 & Note 2 are found
        assertEquals("Note 1 and/or Note 2 are not found", expected, actual); 
    }

    @Override
    public void tearDown() throws Exception {
        //Robotium will finish all the activities that have been opened
        solo.finishOpenedActivities();
    }
}

This is the StackTrace

java.lang.NoClassDefFoundError: com.jayway.android.robotium.solo.Solo
at com.example.android.notepad.test.NotePadTest.setUp(NotePadTest.java:37)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:537)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551)
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
srinivasv
  • 125
  • 8
  • can you make a post with your answer so other people can benefitin case of errors like this? – Luiggi Mendoza Mar 31 '12 at 16:56
  • "NoClassDefFoundError" is due to android sdk upgrade to version 17 . we need to check robotium in "order and export" tab in java build path.But i dint still find solution for constructor deprecated warring . – srinivasv Apr 02 '12 at 05:15
  • This is not a problem of version 17 YOU CAN FIND PERFECT SOLUTION FROM HERE : **http://stackoverflow.com/questions/9875029/android-robotium-noclassdeffounderror** – Vishal Thakarshibhai Viradia Aug 24 '12 at 09:03

3 Answers3

4

"NoClassDefFoundError" is due to android sdk upgrade to version 17 . we need to check robotium in "order and export" tab in java build path.But i dint still find solution for constructor deprecated warring .

srinivasv
  • 125
  • 8
2

I know its too late. But It may help others. I also had the same problem. I resolved it by only writing the class name under super.

Instead of

super("com.example.android.notepad", NotesList.class);

write only

super(NotesList.class);
Sariban D'Cl
  • 2,197
  • 2
  • 28
  • 42
0

May be you use robotium library with low version, please update it to 3.5 at

http://code.google.com/p/robotium/downloads/detail?name=robotium-solo-3.5.1.jar

Note: Your Project -> click mouse right -> Properties -> Java Build Path -> chose tab Libraries -> click button Add JARs... -> browse to robotium-solo-3.5.1.jar -> Click to button OK on popup

Change to tab Order and Export -> click chose robotium-solo-3.5.1.jar -> OK

Thien Nguyen
  • 928
  • 10
  • 12
  • "Thien Nguyen" your idea is not correct. i try by using "robotium-solo-3.6.jar" but still problem "ActivityInstrumentationTestCase2(String, Class) is deprecated" is there. but thanks for help. – VISHAL VIRADIA Feb 04 '13 at 09:14