@Override
 public void setUp() throws Exception {
   super.setUp();
   final Context targetContext = getInstrumentation().getTargetContext();
   final Application app = Instrumentation.newApplication(TestForceApp.class, targetContext);
   getInstrumentation().callApplicationOnCreate(app);
   eq = new EventsListenerQueue();
   if (!SalesforceSDKManager.hasInstance()) {
     eq.waitForEvent(EventsObservable.EventType.AppCreateComplete, 5000);
   }
   SalesforceSDKManager.getInstance()
       .getPasscodeManager()
       .setPasscodeHash(ClientManagerTest.TEST_PASSCODE_HASH);
   SalesforceSDKManager.getInstance().setAdditionalOauthKeys(createAdditionalOauthKeys());
 }
  @Override
  public void setUp() throws Exception {

    if (testResults == null || !testResults.containsKey(jsSuite)) {
      if (testResults == null) {
        testResults = new HashMap<String, Map<String, TestResult>>();
      }

      if (!testResults.containsKey(jsSuite)) {
        testResults.put(jsSuite, new HashMap<String, TestResult>());
      }

      // Wait for app initialization to complete
      EventsListenerQueue eq = new EventsListenerQueue();
      if (!SalesforceSDKManager.hasInstance()) {
        eq.waitForEvent(EventType.AppCreateComplete, 5000);
      }

      // Start main activity
      Instrumentation instrumentation = getInstrumentation();
      final Intent intent = new Intent(Intent.ACTION_MAIN);
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.setClassName(
          instrumentation.getTargetContext(),
          SalesforceSDKManager.getInstance().getMainActivityClass().getName());
      SalesforceDroidGapActivity activity =
          (SalesforceDroidGapActivity) instrumentation.startActivitySync(intent);

      // Block until the javascript has notified the container that it's ready
      TestRunnerPlugin.readyForTests.take();

      // Now run all the tests and collect the resuts in testResults
      for (String testName : getTestNames()) {
        final String jsCmd =
            "javascript:"
                + "navigator.testrunner.setTestSuite('"
                + jsSuite
                + "');"
                + "navigator.testrunner.startTest('"
                + testName
                + "');";
        final CordovaWebView appView = activity.getAppView();
        if (appView != null) {
          appView
              .getView()
              .post(
                  new Runnable() {
                    @Override
                    public void run() {
                      appView.loadUrl(jsCmd);
                    }
                  });
        }
        Log.i(getClass().getSimpleName(), "running test:" + testName);

        // Block until test completes or times out
        TestResult result = null;
        int timeout = getMaxRuntimeInSecondsForTest(testName);
        try {
          result = TestRunnerPlugin.testResults.poll(timeout, TimeUnit.SECONDS);
          if (result == null) {
            result =
                new TestResult(
                    testName, false, "Timeout (" + timeout + " seconds) exceeded", timeout);
          }
        } catch (Exception e) {
          result = new TestResult(testName, false, "Test failed", timeout);
        }
        Log.i(getClass().getSimpleName(), "done running test:" + testName);

        // Save result
        testResults.get(jsSuite).put(testName, result);
      }

      // Cleanup
      eq.tearDown();
      activity.finish();
    }
  }