huaminhquang / android-test-kit

Automatically exported from code.google.com/p/android-test-kit
0 stars 0 forks source link

GoogleInstrumentationTestRunner needs to provide access to AndroidTestRunner #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Feature Request for GoogleInstrumentationTestRunner:

The GoogleInstrumentationTestRunner needs to provide access to 
AndroidTestRunner in order to be able to add TestListeners. When extending from 
the GoogleInstrumentationTestRunner, a custom TestRunner has no way of adding 
own listeners to the AndroidTestRunner.

The only way I was able to do it as a workaround was to use reflection in my 
custom TestRunner:

@Override
    public void start() {
        mListener = new JUnitReportListener(getContext(), getTargetContext(), mReportFile, mReportDir, mFilterTraces, mMultiFile);
        try {
            Class<?> c = getClass();
            Field bridgeTestRunner = c.getSuperclass().getDeclaredField("bridgeTestRunner");
            bridgeTestRunner.setAccessible(true);
            Object obj = bridgeTestRunner.get(this);
            Method m = obj.getClass().getDeclaredMethod("getAndroidTestRunner", null);
            AndroidTestRunner androidTestRunner = (AndroidTestRunner)m.invoke(obj);
            androidTestRunner.addTestListener(mListener);
        } catch (NoSuchFieldException x) {
            Log.e(LOG_TAG, x.toString());
        } catch (SecurityException e) {
            Log.e(LOG_TAG, e.toString());
          } catch (NoSuchMethodException e) {
              Log.e(LOG_TAG, e.toString());
        } catch (IllegalAccessException x) {
            Log.e(LOG_TAG, x.toString());
        } catch (InvocationTargetException e) {
            Log.e(LOG_TAG, e.toString());
        }
      super.start();
    }

Please see thread in discussion group:
https://groups.google.com/forum/#!topic/android-test-kit-discuss/_Lu3odqITj0

Original issue reported on code.google.com by mario.bo...@gmail.com on 12 Nov 2013 at 9:59

GoogleCodeExporter commented 9 years ago

Original comment by vale...@google.com on 12 Nov 2013 at 6:25

GoogleCodeExporter commented 9 years ago
fixed in 1.1

Original comment by thoma...@google.com on 9 Jan 2014 at 12:32