Exemplo n.º 1
0
 /** @param suite the suite to add to the model. */
 private void addSuite(Type type, TestSuite suite) {
   for (Enumeration<Test> e = suite.tests(); e.hasMoreElements(); ) {
     Test test = e.nextElement();
     if (test instanceof TestSuite) {
       addSuite(type, (TestSuite) test);
     } else {
       inventory.put(test.toString(), test);
       testCasesType.put(test.toString(), type);
     }
   }
 }
Exemplo n.º 2
0
 private String getName(Test test) {
   if (test instanceof TestCase) {
     return ((TestCase) test).getName();
   } else {
     return test.toString();
   }
 }
Exemplo n.º 3
0
 /**
  * JUnit 3.7 introduces TestCase.getName() and subsequent versions of JUnit remove the old name()
  * method. This method provides access to the name of a TestCase via reflection that is supposed
  * to work with version before and after JUnit 3.7.
  *
  * <p>since Ant 1.5.1 this method will invoke &quot;<code>public
  * String getName()</code>&quot; on any implementation of Test if it exists.
  *
  * <p>Since Ant 1.7 also checks for JUnit4TestCaseFacade explicitly. This is used by
  * junit.framework.JUnit4TestAdapter.
  *
  * @param t the test.
  * @return the name of the test.
  */
 public static String getTestCaseName(Test t) {
   if (t != null && t.getClass().getName().equals("junit.framework.JUnit4TestCaseFacade")) {
     // Self-describing as of JUnit 4 (#38811). But trim "(ClassName)".
     String name = t.toString();
     if (name.endsWith(")")) {
       int paren = name.lastIndexOf('(');
       return name.substring(0, paren);
     } else {
       return name;
     }
   }
   if (t instanceof TestCase && testCaseName != null) {
     try {
       return (String) testCaseName.invoke(t, new Object[0]);
     } catch (Throwable e) {
       // ignore
     }
   } else {
     try {
       Method getNameMethod = null;
       try {
         getNameMethod = t.getClass().getMethod("getName", new Class[0]);
       } catch (NoSuchMethodException e) {
         getNameMethod = t.getClass().getMethod("name", new Class[0]);
       }
       if (getNameMethod != null && getNameMethod.getReturnType() == String.class) {
         return (String) getNameMethod.invoke(t, new Object[0]);
       }
     } catch (Throwable e) {
       // ignore
     }
   }
   return "unknown";
 }
Exemplo n.º 4
0
 @Override
 public String toString() {
   if (mDelegate != null) {
     return mDelegate.toString();
   } else {
     return mDesc.toString();
   }
 }
Exemplo n.º 5
0
    @Override
    public void run() {
      Collection<TestInventory> inventories = ServiceLocator.get().getAll(TestInventory.class);
      for (TestInventory i : inventories) {
        for (Type type : scope) {
          TestSuite suite = i.getTestSuite(type);
          if (suite.testCount() > 0) {
            addSuite(type, suite);
          }
        }
      }

      for (Test t : inventory.values()) {
        Map<String, Object> testWithProps = Maps.newHashMap();
        testWithProps.put("name", t.toString());
        testWithProps.put("selected", false);
        testWithProps.put("status", "Not Run Yet");
        testWithProps.put("exception", "");
        testWithProps.put("isHidden", "");
        testWithProps.put("type", testCasesType.get(t.toString()).toString().toLowerCase());
        testWithProps.put("isPerf", t instanceof PerfExecutorTest);
        testWithProps.put("perfInfo", "");

        String url = "";
        if (t instanceof ComponentTestCase) {
          url = ((ComponentTestCase) t).getAppUrl();
        }

        if (t instanceof PerfExecutorTest) {
          // url = ((PerfExecutorTest) t).generateUrl();
          List<String> urls = ((PerfExecutorTest) t).generateUrl();
          if (urls.size() > 1) {
            for (String u : urls) {
              testWithProps.put("jsConsole", u);
              testsWithPropsMap.put(t.toString(), testWithProps);
            }
            return;
          }
          url = urls.get(0);
        }

        testWithProps.put("jsConsole", url);
        testsWithPropsMap.put(t.toString(), testWithProps);
      }
    }
Exemplo n.º 6
0
 /** @return TestCase.getName() or Test.toString() or "nullTest" */
 public static String safeTestName(Test test) {
   if (test instanceof TestCase) {
     return ((TestCase) test).getName();
   } else if (null != test) {
     return test.toString();
   } else {
     return "nullTest";
   }
 }
Exemplo n.º 7
0
 public TestInfo(Test test, SuiteInfo suiteInfo) {
   this.test = test;
   this.suiteInfo = suiteInfo;
   String testName = test.toString();
   testName = testName.substring(0, testName.indexOf('('));
   methodName = testName;
   name = testName.substring(4);
   message = Messages.getInstance().getString("UI.USER_TEST_SUITE_NOT_RUN"); // $NON-NLS-1$
   result = new TestResult();
   result.addListener(this);
 }
  protected static String getMethodName(Test test) {
    String className;
    String desc = test.toString();
    Matcher matcher = methodpattern.matcher(desc);
    if (matcher.matches()) {
      className = matcher.group(1);

    } else {
      className = desc;
    }

    return className;
  }
 public void addFailure(Test test, AssertionFailedError t) {
   StringBuffer sb = new StringBuffer();
   sb.append(test.toString());
   sb.append("\n");
   StringWriter sw = new StringWriter();
   t.printStackTrace(new PrintWriter(sw, true));
   sb.append(sw.toString());
   Log.getLogWriter().severe("zzzzzFAILURE IN " + test, t);
   // reportFailure(test, sb.toString());
   lastFailClass = getClassName(test);
   lastFailMethod = getMethodName(test);
   lastThrowable = t;
 }
Exemplo n.º 10
0
 /** Tries to find the name of the class which a test represents across JUnit 3 and 4. */
 static String getTestCaseClassName(Test test) {
   String className = test.getClass().getName();
   if (test instanceof JUnitTaskMirrorImpl.VmExitErrorTest) {
     className = ((JUnitTaskMirrorImpl.VmExitErrorTest) test).getClassName();
   } else if (className.equals("junit.framework.JUnit4TestCaseFacade")) {
     // JUnit 4 wraps solo tests this way. We can extract
     // the original test name with a little hack.
     String name = test.toString();
     int paren = name.lastIndexOf('(');
     if (paren != -1 && name.endsWith(")")) {
       className = name.substring(paren + 1, name.length() - 1);
     }
   }
   return className;
 }
Exemplo n.º 11
0
 /**
  * Called when a test has failed.
  *
  * @param test The test in which the failure occurred.
  * @param t The exception that was raised.
  */
 public void addFailure(Test test, AssertionFailedError e) {
   Log.e(TAG, "Failure while running " + test.toString(), e);
   mFailed = true;
 }
Exemplo n.º 12
0
 public void endTest(Test test) {
   log.info("[END] " + test.toString());
 }
 /**
  * Implemented method of the interface TestListener which will listen for an mError while
  * running the test.
  *
  * @param test
  */
 public void addError(Test test, Throwable t) {
   mError = true;
   failed(test.toString(), t);
 }
Exemplo n.º 14
0
 public synchronized void addFailure(Test test, AssertionFailedError t) {
   log.error("[F] " + test.toString() + " : " + t.getMessage());
 }
Exemplo n.º 15
0
 public synchronized void startTest(Test test) {
   log.info("[START] " + test.toString());
 }
Exemplo n.º 16
0
 /*  68:    */
 /*  69:    */ private String getName(Test test) /*  70:    */ {
   /*  71: 57 */ if ((test instanceof TestCase)) {
     /*  72: 58 */ return ((TestCase) test).getName();
     /*  73:    */ }
   /*  74: 60 */ return test.toString();
   /*  75:    */ }
Exemplo n.º 17
0
 //////////////////////////////////////
 // TestListener implementation
 //////////////////////////////////////
 public synchronized void addError(Test test, Throwable t) {
   log.error("[E] " + test.toString() + " : " + t.getMessage(), t);
 }
  /*
  This class determines if more suites are added to this class then adds all individual
  test classes to a test suite for run
   */
  public void run(String className) {
    try {
      mClassName = className;
      Class clazz = mContext.getClassLoader().loadClass(className);
      Method method = getChildrenMethod(clazz);
      if (method != null) {
        String[] children = getChildren(method);
        run(children);
      } else if (mRunnableClass.isAssignableFrom(clazz)) {
        Runnable test = (Runnable) clazz.newInstance();
        TestCase testcase = null;
        if (test instanceof TestCase) {
          testcase = (TestCase) test;
        }
        Throwable e = null;
        boolean didSetup = false;
        started(className);
        try {
          if (testcase != null) {
            testcase.setUp(mContext);
            didSetup = true;
          }
          if (mMode == PERFORMANCE) {
            runInPerformanceMode(test, className, false, className);
          } else if (mMode == PROFILING) {
            // Need a way to mark a test to be run in profiling mode or not.
            startProfiling();
            test.run();
            finishProfiling();
          } else {
            test.run();
          }
        } catch (Throwable ex) {
          e = ex;
        }
        if (testcase != null && didSetup) {
          try {
            testcase.tearDown();
          } catch (Throwable ex) {
            e = ex;
          }
        }
        finished(className);
        if (e == null) {
          passed(className);
        } else {
          failed(className, e);
        }
      } else if (mJUnitClass.isAssignableFrom(clazz)) {
        Throwable e = null;
        // Create a Junit Suite.
        JunitTestSuite suite = new JunitTestSuite();
        Method[] methods = getAllTestMethods(clazz);
        for (Method m : methods) {
          junit.framework.TestCase test = (junit.framework.TestCase) clazz.newInstance();
          test.setName(m.getName());

          if (test instanceof AndroidTestCase) {
            AndroidTestCase testcase = (AndroidTestCase) test;
            try {
              testcase.setContext(mContext);
              testcase.setTestContext(mContext);
            } catch (Exception ex) {
              Log.i("TestHarness", ex.toString());
            }
          }
          suite.addTest(test);
        }
        if (mMode == PERFORMANCE) {
          final int testCount = suite.testCount();

          for (int j = 0; j < testCount; j++) {
            Test test = suite.testAt(j);
            started(test.toString());
            try {
              runInPerformanceMode(test, className, true, test.toString());
            } catch (Throwable ex) {
              e = ex;
            }
            finished(test.toString());
            if (e == null) {
              passed(test.toString());
            } else {
              failed(test.toString(), e);
            }
          }
        } else if (mMode == PROFILING) {
          // Need a way to mark a test to be run in profiling mode or not.
          startProfiling();
          junit.textui.TestRunner.run(suite);
          finishProfiling();
        } else {
          junit.textui.TestRunner.run(suite);
        }
      } else {
        System.out.println(
            "Test wasn't Runnable and didn't have a" + " children method: " + className);
      }
    } catch (ClassNotFoundException e) {
      Log.e("ClassNotFoundException for " + className, e.toString());
      if (isJunitTest(className)) {
        runSingleJunitTest(className);
      } else {
        missingTest(className, e);
      }
    } catch (InstantiationException e) {
      System.out.println("InstantiationException for " + className);
      missingTest(className, e);
    } catch (IllegalAccessException e) {
      System.out.println("IllegalAccessException for " + className);
      missingTest(className, e);
    }
  }
 public void addFailure(Test test, junit.framework.AssertionFailedError t) {
   mError = true;
   failed(test.toString(), t);
 }
 /**
  * Implemented method of the interface TestListener which will listen for the end of the test.
  *
  * @param test
  */
 public void endTest(Test test) {
   finished(test.toString());
   if (!mError) {
     passed(test.toString());
   }
 }
 public void startTest(Test test) {
   this.startTime = System.currentTimeMillis();
   String s = "zzzzzSTART " + test;
   Log.getLogWriter().info(s);
   testInProgress = test.toString();
 }
 /**
  * Implemented method of the interface TestListener which will listen for the start of a test.
  *
  * @param test
  */
 public void startTest(Test test) {
   started(test.toString());
 }
Exemplo n.º 23
0
 /**
  * Called when an error has occurred while running a test.
  *
  * <p>Note that an error usually means a problem with the test or test harness, not with the code
  * under test.
  *
  * @param test The test in which the error occurred.
  * @param t The exception that was raised.
  */
 @Override
 public void addError(Test test, Throwable t) {
   Log.e(TAG, "Error while running " + test.toString(), t);
   mFailed = true;
 }
Exemplo n.º 24
0
 /**
  * This constructor extracts the needed information from the given test.
  *
  * @param test Test to analyze
  */
 public TestInfos(Test test) {
   className = test.getClass().getName();
   String _methodName = test.toString();
   methodName = _methodName.substring(0, _methodName.indexOf('('));
 }