Android InstrumentationTestCase - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android InstrumentationTestCase class.

This code example shows how to use the following methods:getInstrumentation
    @Mock 
    Bundle bundle;
 
    @Before 
    public void setup() { 
        when(testCase.getInstrumentation()).thenReturn(instrumentation);
    } 
} 
6
CodeRank
This code example shows how to use the following methods:runTestOnUiThread
            final ContentView view, TestCallbackHelperContainer viewClient, final String code)
                    throws Throwable { 
        TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper 
                onEvaluateJavaScriptResultHelper = viewClient.getOnEvaluateJavaScriptResultHelper();
        int currentCallCount = onEvaluateJavaScriptResultHelper.getCallCount();
        test.runTestOnUiThread(new Runnable() {
            @Override 
            public void run() { 
                mRequestId = view.evaluateJavaScript(code);
            } 
        }); 
        onEvaluateJavaScriptResultHelper.waitForCallback(currentCallCount);
        Assert.assertEquals("Response ID mismatch when evaluating JavaScript.",
                mRequestId, onEvaluateJavaScriptResultHelper.getId());
        return onEvaluateJavaScriptResultHelper.getJsonResult();
    } 
 
    /** 
     * Executes the given snippet of JavaScript code but does not wait for the result. 
     */ 
5
CodeRank
This code example shows how to use the following methods:injectInstrumentation
This code example shows how to use the following methods:getTargetContext, injectInstrumentation
    } 
 
    @Override 
    public void runTest(Test test, TestResult result) {
        if (test instanceof AndroidTestCase) {
            ((AndroidTestCase)test).setContext(mInstr.getTargetContext());
        } 
        if (test instanceof InstrumentationTestCase) {
            ((InstrumentationTestCase)test).injectInstrumentation(mInstr);
        } 
        super.runTest(test, result);
    } 
 
    Instrumentation getInstrumentation() {
        return mInstr;
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getInstrumentation, runTestOnUiThread
This code example shows how to use the following methods:getInstrumentation
This code example shows how to use the following methods:getInstrumentation
        this.instrumentationTestCase = instrumentationTestCase;
    } 
 
    @Override 
    public Resources getResources() {
        return instrumentationTestCase.getInstrumentation().getTargetContext().getResources();
    } 
 
    @Override 
    public Resources.Theme getTheme() {
        return instrumentationTestCase.getInstrumentation().getTargetContext().getTheme();
    } 
 
    @Override 
    public Object getSystemService(String name) {
        if (Context.LAYOUT_INFLATER_SERVICE.equals(name)) {
            return instrumentationTestCase.getInstrumentation().getTargetContext().getSystemService(name);
        } 
        return super.getSystemService(name);
    } 
4
CodeRank
This code example shows how to use the following methods:getInstrumentation
This code example shows how to use the following methods:getInstrumentation
This code example shows how to use the following methods:sendKeys
  public static void tapDialogNegativeButton(InstrumentationTestCase testCase) {
    // The order of the buttons is reversed from ICS onwards 
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
      testCase.sendKeys("DPAD_RIGHT DPAD_CENTER");
    } else { 
      testCase.sendKeys("DPAD_LEFT DPAD_CENTER");
    } 
  } 
 
  /** 
   * Taps the negative button of a currently displayed dialog. This method assumes that a button 
   * of the dialog is currently selected. 
   * 
   * @see #tapDialogNegativeButton(InstrumentationTestCase) 
   */ 
  public static void tapDialogPositiveButton(InstrumentationTestCase testCase) {
    // The order of the buttons is reversed from ICS onwards 
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
      testCase.sendKeys("DPAD_LEFT DPAD_CENTER");
    } else { 
3
CodeRank

Related Android InstrumentationTestCase Questions & Answers:

See Code Examples for Android InstrumentationTestCase Methods: