mercredi 13 décembre 2017

How to test element of custom sdk android unit test

i start learning android unit tests . But its looks very hard to find some good guide or info. Every example have a stupid example about 2+2 = 4

Say i write little sdk which has few functions

MySdk.Init(Context context)
MySdk.CallTask()

I create androidTest file

how i should call my sdk functions to check how they work ? somewhere required parameters like int/string/context

I just realy not understand , please help me some body its how i trying

public class AndroidTest {
    private Activity context;


//default test
@Test
public void addition_correct() throws Exception {
    assertEquals(4, 2 + 2);
}

@Test
public void checkContext() {
    context = getActivity();
    assertNotNull(context);
}

@Test
public void testInitPhase() {

    MySdk.Init(context, new SdkInitializationListener() {
        @Override
        public void onInitializationSuccessful(String adv_id) {
            assert (adv_id != null);
        }

        @Override
        public void onInitializationError() {

        }
    });
}

}

For context i was tried context = new mockContext(); Its passed as context = null and my sdk failed with initialization. Please some one expert give me right path. What should i todo . Pleaseee.

Aucun commentaire:

Enregistrer un commentaire