private void runTestUnderCursor() {
   // This only works when there's one applicable run configuations, otherwise a popup would show
   // up.
   myEditor.invokeAction(EditorFixture.EditorAction.RUN_FROM_CONTEXT);
   myProjectFrame.waitForBackgroundTasksToFinish();
 }
  /**
   * This covers all functionality that we expect from AS when it comes to unit tests:
   *
   * <ul>
   *   <li>Tests can be run from the editor.
   *   <li>Results are correctly reported in the Run window.
   *   <li>The classpath when running tests is correct.
   *   <li>You can fix a test and changes are picked up the next time tests are run (which means the
   *       correct gradle tasks are run).
   * </ul>
   */
  @Test
  @IdeGuiTest
  public void unitTestingSupport() throws IOException {
    myProjectFrame = importProjectAndWaitForProjectSyncToFinish("SimpleApplicationWithUnitTests");

    BuildVariantsToolWindowFixture buildVariants = myProjectFrame.getBuildVariantsWindow();
    buildVariants.activate();
    buildVariants.selectUnitTests();

    // Open the test file:
    myEditor = myProjectFrame.getEditor();
    myEditor.open("app/src/test/java/google/simpleapplication/UnitTest.java");

    // Run the test case that is supposed to pass:
    myEditor.moveTo(myEditor.findOffset("passing", "Test", true));

    runTestUnderCursor();

    UnitTestTreeFixture unitTestTree = getTestTree("UnitTest.passingTest");
    assertTrue(unitTestTree.isAllTestsPassed());

    // Run the whole class, the second test case will fail:
    myEditor.requestFocus();
    myEditor.moveTo(myEditor.findOffset("class Unit", "Test", true));

    runTestUnderCursor();

    unitTestTree = getTestTree("UnitTest");
    assertEquals(1, unitTestTree.getFailingTestsCount());

    // Fix the failing test and re-run the tests.
    myEditor.requestFocus();
    myEditor.moveTo(myEditor.findOffset("(5", ",", true));
    myEditor.invokeAction(EditorFixture.EditorAction.BACK_SPACE);
    myEditor.enterText("4");

    unitTestTree.getContent().rerun();
    myProjectFrame.waitForBackgroundTasksToFinish();
    unitTestTree = getTestTree("UnitTest");
    assertTrue(unitTestTree.isAllTestsPassed());
  }