类android.test.InstrumentationTestCase源码实例Demo

下面列出了怎么用android.test.InstrumentationTestCase的API类实例代码及写法,或者点击链接到github查看源代码。

/**
 *
 */
public void setUpToFindComponet(String target, InstrumentationTestCase test){
    int max = 60;
    int count = 0;
    while(mCaseListIndexView.size() == 0){

        if (count < max){
            TouchUtils.dragQuarterScreenUp(test, WXPageActivity.wxPageActivityInstance );
            mViewGroup = (ViewGroup) WXPageActivity.wxPageActivityInstance.findViewById(R.id.container);
            mCaseListIndexView = ViewUtil.findViewWithText(mViewGroup, target);
            count ++;
        }
        else{
            break;
        }

    }
}
 
/**
 *
 */
public void setUpToFindComponet(String target, InstrumentationTestCase test){
    int max = 60;
    int count = 0;
    while(mCaseListIndexView.size() == 0){

        if (count < max){
            TouchUtils.dragQuarterScreenUp(test, WXPageActivity.wxPageActivityInstance );
            mViewGroup = (ViewGroup) WXPageActivity.wxPageActivityInstance.findViewById(R.id.container);
            mCaseListIndexView = ViewUtil.findViewWithText(mViewGroup, target);
            count ++;
        }
        else{
            targetComponetNotFound = true;
        }

    }
}
 
/**
 *
 */
public void setUpToFindComponet(String target, InstrumentationTestCase test){
    int max = 60;
    int count = 0;
    while(mCaseListIndexView.size() == 0){

        if (count < max){
            TouchUtils.dragQuarterScreenUp(test, WXPageActivity.wxPageActivityInstance );
            mViewGroup = (ViewGroup) WXPageActivity.wxPageActivityInstance.findViewById(R.id.container);
            mCaseListIndexView = ViewUtil.findViewWithText(mViewGroup, target);
            count ++;
        }
        else{
            break;
        }

    }
}
 
源代码4 项目: android-test   文件: AndroidTestResult.java
@Override
protected void run(final TestCase test) {
  if (test instanceof AndroidTestCase) {
    ((AndroidTestCase) test).setContext(instr.getTargetContext());
  }
  if (test instanceof InstrumentationTestCase) {
    ((InstrumentationTestCase) test).injectInstrumentation(instr);
  }
  super.run(test);
}
 
public static void saveAndRestoreInstanceState(final InstrumentationTestCase test, final Activity activity) throws Throwable {
    test.runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            Bundle outState = new Bundle();
            test.getInstrumentation().callActivityOnSaveInstanceState(activity, outState);
            test.getInstrumentation().callActivityOnPause(activity);
            test.getInstrumentation().callActivityOnResume(activity);
            test.getInstrumentation().callActivityOnRestoreInstanceState(activity, outState);
        }
    });
    test.getInstrumentation().waitForIdleSync();
}
 
public static void swipeHorizontally(InstrumentationTestCase test, View v, Direction direction) {
    int[] xy = new int[2];
    v.getLocationOnScreen(xy);

    final int viewWidth = v.getWidth();
    final int viewHeight = v.getHeight();

    float distanceFromEdge = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            v.getResources().getDisplayMetrics());
    float xStart = xy[0] + ((direction == Direction.LEFT) ? (viewWidth - distanceFromEdge) : distanceFromEdge);
    float xEnd = xy[0] + ((direction == Direction.LEFT) ? distanceFromEdge : (viewWidth - distanceFromEdge));
    float y = xy[1] + (viewHeight / 2.0f);

    TouchUtils.drag(test, xStart, xEnd, y, y, DRAG_STEP_COUNT);
}
 
public static void swipeVertically(InstrumentationTestCase test, View v, Direction direction) {
    int[] xy = new int[2];
    v.getLocationOnScreen(xy);

    final int viewWidth = v.getWidth();
    final int viewHeight = v.getHeight();

    float distanceFromEdge = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            v.getResources().getDisplayMetrics());
    float x = xy[0] + (viewWidth / 2.0f);
    float yStart = xy[1] + ((direction == Direction.UP) ? (viewHeight - distanceFromEdge) : distanceFromEdge);
    float yEnd = xy[1] + ((direction == Direction.UP) ? distanceFromEdge : (viewHeight - distanceFromEdge));

    TouchUtils.drag(test, x, x, yStart, yEnd, DRAG_STEP_COUNT);
}
 
源代码8 项目: ExoPlayer-Offline   文件: TestUtil.java
public static void setUpMockito(InstrumentationTestCase instrumentationTestCase) {
  // Workaround for https://code.google.com/p/dexmaker/issues/detail?id=2.
  System.setProperty("dexmaker.dexcache",
      instrumentationTestCase.getInstrumentation().getTargetContext().getCacheDir().getPath());
  MockitoAnnotations.initMocks(instrumentationTestCase);
}
 
源代码9 项目: incubator-weex-playground   文件: ViewUtil.java
public static void dragQuarterScreenUp(InstrumentationTestCase test, Activity activity) {

        TouchUtils.dragQuarterScreenUp(test, activity);
    }
 
/**
 * Initializes the webView with a WebViewClient, WebChromeClient, and PictureListener to prepare for
 * loadUrlAndWaitForCompletion. A new WebViewOnUiThread should be called during setUp so as to reinitialize between
 * calls.
 * 
 * @param test
 *            The test in which this is being run.
 * @param webView
 *            The webView that the methods should call.
 * @see loadUrlAndWaitForCompletion
 */
public AmazonWebViewOnUiThread(InstrumentationTestCase test,
    CordovaWebView webView) {
    mTest = test;
    mWebView = webView;
}