简体   繁体   中英

in robotium how to handle multiple classes

i am having the same problem i am using 3 classes(classA, ClassB , ClassC ), and solo_d class, in my ClassC i am having test and in ClassA and ClassB i am using solo.sleep only

public class ClassA extends Solo_d{
public void click_on_save(){
Log.v("Test" , "Test in classA");
solo.sleep(5000);                // getting error null pointer exception 
solo.clickOnText("Saved")
}}


public class ClassC extends Solo_d {
ClassA aa = new ClassA();
@Test
public void test001(){
Log.v("Test" , "Test Start ");
aa.click_on_save();
}}

and i am using ClassB same as classA and using in ClassC

in Solo_d class i have given proper Activity and solo definition its working fine individual and also working fine if i am using as ClassB extends Solo_d ClassA extends ClassB
ClassC extends ClassA but if i do not want to extend ClassA in ClassB , ClassB in ClassC it will be difficult to know the sequence of the inheritance

but i am getting NullPointerException anybody can help on this

I suppose you need to add constructor to class A and remove "extends Solo_d"

public class ClassA{

    static Solo solo;

    //contructor
    public ClassA(Solo _solo){
      solo = _solo
    }

    public void click_on_save(){
    Log.v("Test" , "Test in classA");
    solo.sleep(5000);
    solo.clickOnText("Saved");
    }
}

and in your ClassC:

public class ClassC extends Solo_d {

    @Test
    public void test001(){
    ClassA aa = new ClassA(solo);
    Log.v("Test" , "Test Start ");
    aa.click_on_save();
    }
}

You could create the same constructor in you ClassC and call it in your Solo_d class (for example, in your setUp() method)

public class ClassC {

    static Solo solo;
    public ClassC(Solo _solo){
        solo = _solo
    }
    ClassA aa = new ClassA(solo);
    @Test
    public void test001(){
    Log.v("Test" , "Test Start ");
    aa.click_on_save();
    }
}

It works for me, hope it will be helpful for you.

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