vendredi 2 août 2019

Testing of Android library with TestNG and Cucumber

Currently I have developed one android library (which contains asynchronous APIs to my Rest APIs server). I have added test scenarios using TestNG. The reason behind creating test app is to enable end use to verify my library rather than I keep maintaining test reports.

Now I am wondering if can I use Cucumber here to write those scenarios in Gherkin language.

In my test application in initial screen I read some configuration for by Rest APIs server. After use will be displayed list of available test cases (can be filtered). Now user can choose which test cases to run and get reports in real time.

// Sample Test cases which I use with TestNG to execute:

public class SampleTestCases {
    GluuTokenResponse gluuAccessToken = null;

    @Test
    public void testLoginHappyFlow() {
        // Read gluu access token
        CountDownLatch countDownLatch = new CountDownLatch(1);
        new Thread(new Runnable() {
            @Override
            public void run() {
                gluuAccessToken = GluuTokenUtils.getGluuTokenForLogin();
                countDownLatch.countDown();
            }
        }).start();

        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        MyLib.ins().doLogin(gluuAccessToken);

    }

}

//How I execute using TestNG:

public class ExecuteTest {

    private final Context mCtx;

    public ExecuteTest(Context context) {
        this.mCtx = context;
    }

    public void run() {
        try {
            TestNG testNG = new TestNG();
            testNG.setTestClasses(new Class[]{SampleTestCases.class});
            testNG.run();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

Basically I am hoping to write cucumber test cases (feature + step guide) and should be able to run through TestNG in Android.

Aucun commentaire:

Enregistrer un commentaire