Alberto Bailac Moreno
Alberto Bailac Moreno

Reputation: 131

How to test ui application android with JUNIT and take screenshots

can I run junit test on Android device and see the application running the test in the device at the same time?

If it is posible, can i take screenshots of the tests ??

I create the testcase, and works. Like this..

public TestCase(Class activityClass) {
    super("com.xxxx.xxxxx", xxxxxx.class);
    // TODO Auto-generated constructor stub
}

@Override
protected void setUp() throws Exception {
    super.setUp();
    LoginActivity mainActivity = getActivity();
    result = (EditText) mainActivity.findViewById(R.id.edit_xxx);
    result.setText("holahola");

    Button btn = (Button) mainActivity.findViewById(R.id.btn_xxx);
    btn.performClick();
}

Upvotes: 1

Views: 1552

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007322

can I run junit test on Android device and see the application running the test in the device at the same time?

Yes, though they run fairly quickly.

If it is posible, can i take screenshots of the tests ?

You are welcome to ask the content View of your activity to draw itself to a Bitmap-backed Canvas, and this should work just fine from a unit test: How to take a screenshot and share it programmatically

Upvotes: 1

Related Questions