@Override
  public Object start(final IApplicationContext context) throws Exception {

    final String[] cmdArguments =
        (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
    Map<String, String> args = null;
    try {
      args = processArgs(cmdArguments);
    } catch (final ArgumentException e) {
      System.err.println(e.getMessage());
      System.err.println(usage());
      return -1;
    }

    JUnitCore junit = new JUnitCore();
    junit.addListener(new MyTextListener());

    if (args.containsKey(ARG_XML_OUT)) {
      final File xmlResultFile = new File(args.get(ARG_XML_OUT));
      JUnitXMLRunListener listener = new JUnitXMLRunListener(xmlResultFile);
      junit.addListener(listener);
    }

    logger.info("Starting regression test");
    logger.info("Platform default encoding: " + Charset.defaultCharset());
    logger.info("Common version: " + getBundleVersion(ProductConstants.PRODUCT_ID_COMMON));
    logger.info("Designer version: " + getBundleVersion(ProductConstants.PRODUCT_ID_DESIGNER));
    logger.info("Titan regression test version: " + getBundleVersion(REGRESSION_TEST_ID));

    Result result = junit.run(MainTestSuite.class);
    printResult(result);
    return IApplication.EXIT_OK;
  }
 private String[] runTests(Class<?>... classes) {
   JUnitCore core = new JUnitCore();
   StringWriter sw = new StringWriter();
   PrintWriter pw = new PrintWriter(sw);
   core.addListener(new JUnit4ProgressRunListener(new SimpleMessageSenderFactory(pw)));
   core.run(classes);
   return sw.toString().split("\n");
 }
예제 #3
0
 public final void run() {
   final JUnitCore jUnitCore = new JUnitCore();
   jUnitCore.addListener(new JUnitTestListener());
   jUnitCore.run(TestContexts.class);
   jUnitCore.run(NextConceptTest.class);
   //    jUnitCore.run(NextImplicationTest.class);
   //    jUnitCore.run(NextClosureTest.class);
 }
 @Override
 public void setUp() {
   runner = new JUnitCore();
   results = new ByteArrayOutputStream();
   PrintStream writer = new PrintStream(results);
   listener = new TextListener(writer);
   runner.addListener(listener);
 }
 @Test
 public void runTestAndVerifyResult() {
   EventCollector collector = new EventCollector();
   JUnitCore core = new JUnitCore();
   core.addListener(collector);
   core.run(classUnderTest);
   assertThat(collector, matcher);
 }
  @Override
  public Object[] query() throws Exception {
    Class<?> klass = getClass().getClassLoader().loadClass(args[0]);

    JUnitCore core = new JUnitCore();
    FitSuiteRunListener listener = new FitSuiteRunListener();
    core.addListener(listener);
    core.run(klass);
    return listener.getResults().toArray();
  }
예제 #7
0
 /**
  * Runs the test classes given in {@param classes}.
  *
  * @returns Zero if all tests pass, non-zero otherwise.
  */
 public static int run(Class[] classes, RunListener listener) {
   JUnitCore junitCore = new JUnitCore();
   junitCore.addListener(listener);
   boolean hasError = false;
   for (@AutoreleasePool Class c : classes) {
     Result result = junitCore.run(c);
     hasError = hasError || !result.wasSuccessful();
   }
   return hasError ? 1 : 0;
 }
예제 #8
0
 public static void runInMain(Class<?> testClass, String[] args)
     throws InitializationError, NoTestsRemainException {
   JUnitCore core = new JUnitCore();
   core.addListener(new TextListener(System.out));
   SLTestRunner suite = new SLTestRunner(testClass);
   if (args.length > 0) {
     suite.filter(new NameFilter(args[0]));
   }
   Result r = core.run(suite);
   if (!r.wasSuccessful()) {
     System.exit(1);
   }
 }
  private RunStatistics runClasses(
      DefaultReporterFactory reporterManagerFactory,
      org.junit.runner.notification.RunListener demultiplexingRunListener,
      Class<?>... classes)
      throws TestSetFailedException {

    JUnitCore jUnitCore = new JUnitCore();

    jUnitCore.addListener(demultiplexingRunListener);
    Computer computer = new Computer();

    jUnitCore.run(computer, classes);
    return reporterManagerFactory.getGlobalRunStatistics();
  }
예제 #10
0
  /**
   * Constructor.
   *
   * @param testRunName Name of the test run the execute
   * @param configPath Path to the configuration file
   * @param listener Optional, a listener for the JUnit Events. If not set the default listener
   *     com.day.qa.test.TestRunListener will be used. Can be used by customer to create their own
   *     reports.
   * @throws Exception if an error occured during execution of the class
   */
  TestRunner(String testRunName, String configPath, RunListener listener) throws Exception {

    // load the config file
    config = new TestRunnerConfig(configPath);

    // instantiate the JUnitCore runner
    jUnitRunner = new JUnitCore();

    // add the listener
    jUnitRunner.addListener(listener);

    // run the tests
    executeTestRun(testRunName);
  }
예제 #11
0
  @Test
  public void failedAssumptionsCanBeDetectedByListeners() {
    assumptionFailures = 0;
    JUnitCore core = new JUnitCore();
    core.addListener(
        new RunListener() {
          @Override
          public void testAssumptionFailure(Failure failure) {
            assumptionFailures++;
          }
        });
    core.run(HasFailingAssumption.class);

    assertThat(assumptionFailures, is(1));
  }
  private RunStatistics runClasses(Class<?>... classes) throws TestSetFailedException {
    HashMap<String, TestSet> classMethodCounts = new HashMap<String, TestSet>();
    final DefaultReporterFactory reporterManagerFactory = createReporterFactory();
    org.junit.runner.notification.RunListener demultiplexingRunListener =
        createRunListener(reporterManagerFactory, classMethodCounts);

    JUnitCore jUnitCore = new JUnitCore();

    jUnitCore.addListener(demultiplexingRunListener);
    Computer computer = new Computer();

    jUnitCore.run(computer, classes);
    reporterManagerFactory.close();
    return reporterManagerFactory.getGlobalRunStatistics();
  }
예제 #13
0
  @Override
  protected int doWork() throws Exception {
    // this is called from the command line, so we should set to use the distributed cluster
    IntegrationTestingUtility.setUseDistributedCluster(conf);
    Class<?>[] classes = findIntegrationTestClasses();
    LOG.info("Found " + classes.length + " integration tests to run:");
    for (Class<?> aClass : classes) {
      LOG.info("  " + aClass);
    }
    JUnitCore junit = new JUnitCore();
    junit.addListener(new TextListener(System.out));
    Result result = junit.run(classes);

    return result.wasSuccessful() ? 0 : 1;
  }
예제 #14
0
파일: JUnitCore.java 프로젝트: sl4mmy/junit
 /**
  * @param system
  * @args args from main()
  */
 private Result runMain(JUnitSystem system, String... args) {
   system.out().println("JUnit version " + Version.id());
   List<Class<?>> classes = new ArrayList<Class<?>>();
   List<Failure> missingClasses = new ArrayList<Failure>();
   for (String each : args)
     try {
       classes.add(Class.forName(each));
     } catch (ClassNotFoundException e) {
       system.out().println("Could not find class: " + each);
       Description description = Description.createSuiteDescription(each);
       Failure failure = new Failure(description, e);
       missingClasses.add(failure);
     }
   RunListener listener = new TextListener(system);
   addListener(listener);
   Result result = run(classes.toArray(new Class[0]));
   for (Failure each : missingClasses) result.getFailures().add(each);
   return result;
 }
예제 #15
0
  public boolean run() throws IOException {
    try {
      m_dir = "testout/junit-" + m_timestamp + "/" + m_testClazz.getCanonicalName() + "/";
      new File(m_dir).mkdirs();

      // redirect std out/err to files
      m_out.addOutputStream(new File(m_dir + "fulloutput.txt"));
      System.setOut(new PrintStream(m_out, true));
      System.setErr(new PrintStream(m_out, true));

      JUnitCore junit = new JUnitCore();
      junit.addListener(this);
      Result r = junit.run(m_testClazz);
      STDOUT.printf("RESULTS: %d/%d\n", r.getRunCount() - r.getFailureCount(), r.getRunCount());
      return true;
    } catch (Exception e) {
      return false;
    } finally {
      m_out.flush();
      System.setOut(STDOUT);
      System.setErr(STDERR);
      m_out.close();
    }
  }
예제 #16
0
 @Before
 public void setUp() {
   jUnitCore.addListener(testListener);
 }
예제 #17
0
  public static int[] replayMetaProgramWith(Class<?> TEST_CLASS) throws Exception {
    System.out.println("******************" + TEST_CLASS.getName() + "******************");

    boolean debug = false;

    JUnitCore core = new JUnitCore();

    // output folder
    File fail = new File("results/fail.replay/" + TEST_CLASS.getName().replace(".", "/"));
    fail.mkdirs();
    File success = new File("results/success.replay/" + TEST_CLASS.getName().replace(".", "/"));
    success.mkdirs();

    String path = "results/fail/" + TEST_CLASS.getName().replace(".", "/");
    File source = new File(path);
    File[] mutants;
    if (source.exists() && source.isDirectory()) {
      mutants = source.listFiles();
    } else {
      throw new Exception(
          "The directory fail or success dosen't exist, or is not a directory, please execute MutantSearchSpaceExplorator.runMetaProgramWith(Class<?> TEST_CLASS) first.");
    }

    // we first run the test suite once to load all classes and their static
    // fields
    // this registers only the executed ifs, so indirectly
    // it collects a kind of trace
    Result result = core.run(TEST_CLASS);

    if (debug) {
      core.addListener(new TextListener(System.out));
    }

    List<Selector> selectors = Selector.getAllSelectors();

    // if (selectors.isEmpty())
    // // There's no hot spot in program. Add one to run it at least once
    // selectors = ImmutableList.of(Selector.of(0, "n/a"));

    List<String> successes = Lists.newArrayList();
    List<String> failures = Lists.newArrayList();
    Multimap<Integer, String> failures2 =
        Multimaps.newListMultimap(Maps.newHashMap(), Lists::newArrayList);

    String[] strOptions = new String[selectors.size()];
    // Execute the test for each hot spot permutation
    // for (int[] options :
    // permutations(selectors.stream().map(Selector::getOptionCount).collect(Collectors.toList())))
    // {

    int nattempts = 0;

    for (int mut = 0; mut < mutants.length; mut++) {
      Config conf = Config.getInitInstance();

      Map<String, Integer> mapedConf =
          conf.getConfig(mutants[mut].getPath()).get(selectors.get(0).getLocationClass().getName());

      Set<String> cles = mapedConf.keySet();

      int[] options = new int[selectors.size()];
      int sel = 0;
      for (String cle : cles) {

        Selector.getSelectorByName(cle).choose(mapedConf.get(cle));
        strOptions[sel] = Selector.getSelectorByName(cle).getChosenOptionDescription();
        for (int o = 0; o < Selector.getSelectorByName(cle).getOptionCount(); o++) {

          boolean value = (o == mapedConf.get(cle)) ? true : false;

          conf.write(
              Selector.getSelectorByName(cle).getLocationClass().getName()
                  + ":"
                  + Selector.getSelectorByName(cle).getId()
                  + ":"
                  + Selector.getSelectorByName(cle).getOption()[o]
                  + ":"
                  + value);
        }
        sel++;
      }

      if (debug) System.out.println("Checking options: " + Arrays.toString(options));

      result = core.run(TEST_CLASS);

      if (result.wasSuccessful()) {
        successes.add(
            "   Worked !!!  -> " + Arrays.toString(options) + " / " + Arrays.toString(strOptions));

        // On essaye avec renameTo
        File dest = new File(success.getPath() + "/" + mutants[mut].getName());
        new File("config.txt").renameTo(dest);
      } else {
        String txt =
            String.format(
                "%s / %s -> It has %s failures out of %s runs in %s ms",
                Arrays.toString(options),
                Arrays.toString(strOptions),
                result.getFailureCount(),
                result.getRunCount(),
                result.getRunTime());
        String txt_trace = String.format("%s", Arrays.toString(strOptions));

        failures.add(txt);
        failures2.put(result.getFailureCount(), txt);
        System.out.println(result.getFailures().get(0).getException());
        File dest = new File(fail.getPath() + "/" + mutants[mut].getName());
        new File("config.txt").renameTo(dest);
      }
    }

    System.out.println("killed " + failures.size());
    System.out.println("alive " + successes.size());

    Selector.reset();

    int[] val = {failures.size(), successes.size()};

    return val;

    // Show result summary
    // Sets.newHashSet(failures2.keys()).forEach(k -> {
    // System.out.println(String.format("\n-- Cases with %s", k));
    // Collection<String> texts = failures2.get(k);
    // if (k <= 2 || texts.size() < 10)
    // texts.forEach(System.out::println);
    // else
    // System.out.println("There are " + texts.size());
    // });

    // failures.forEach(System.out::println);

    // System.out.println();
    //
    // if (successes.isEmpty())
    // System.out.println("Oops, sorry, we could find a successful option");
    // else
    // successes.forEach(System.out::println);

  }
 public static void main(String[] args) {
   JUnitCore core = new JUnitCore();
   core.addListener(new CalcListener());
   core.run(MathFunctionTest.class);
 }
예제 #19
0
 private Result runImpl(Test test) {
   JUnitCore runner = new JUnitCore();
   TextListener txtListener = new TextListener(System.out);
   runner.addListener(txtListener);
   return runner.run(test);
 }
 public ManagerRunningTests() {
   junit = new JUnitCore();
   listener = new JUnitTestRunListener();
   junit.addListener(listener);
 }
예제 #21
0
    public static void userMain(String[] args) {
      H2O.main(args);
      TestUtil.stall_till_cloudsize(NODES);

      List<Class> tests = new ArrayList<Class>();

      // Classes to test:
      // tests = JUnitRunner.all();

      // Neural Net - deprecated
      //      tests.add(NeuralNetSpiralsTest.class); //compare NeuralNet vs reference
      //      tests.add(NeuralNetIrisTest.class); //compare NeuralNet vs reference

      // Chunk tests
      //      tests.add(C0LChunkTest.class);
      //      tests.add(C0DChunkTest.class);
      //      tests.add(C1ChunkTest.class);
      //      tests.add(C1NChunkTest.class);
      //      tests.add(C1SChunkTest.class);
      //      tests.add(C2ChunkTest.class);
      //      tests.add(C2SChunkTest.class);
      //      tests.add(C4ChunkTest.class);
      //      tests.add(C4FChunkTest.class);
      //      tests.add(C4SChunkTest.class);
      //      tests.add(C8ChunkTest.class);
      //      tests.add(C8DChunkTest.class);
      //      tests.add(C16ChunkTest.class);
      //      tests.add(CBSChunkTest.class);
      //      tests.add(CX0ChunkTest.class);
      //      tests.add(CXIChunkTest.class);
      //      tests.add(CXDChunkTest.class);
      //      tests.add(VecTest.class);

      // Deep Learning tests
      //      tests.add(DeepLearningVsNeuralNet.class); //only passes for NODES=1, not clear why
      //      tests.add(DeepLearningAutoEncoderTest.class); //test Deep Learning convergence
      //      tests.add(DeepLearningAutoEncoderCategoricalTest.class); //test Deep Learning
      // convergence
      //      tests.add(DeepLearningSpiralsTest.class); //test Deep Learning convergence
      //      tests.add(DeepLearningIrisTest.Short.class); //compare Deep Learning vs reference
      //      tests.add(DeepLearningIrisTest.Long.class); //compare Deep Learning vs reference
      tests.add(DeepLearningProstateTest.Short.class); // test Deep Learning
      //      tests.add(DeepLearningMissingTest.class); //test Deep Learning
      //      tests.add(DeepLearningProstateTest.Long.class); //test Deep Learning
      //      tests.add(NeuronsTest.class); //test Deep Learning
      //      tests.add(MRUtilsTest.class); //test MR sampling/rebalancing
      //      tests.add(DropoutTest.class); //test NN Dropput

      //      tests.add(ParserTest2.class);
      //      tests.add(ParserTest2.ParseAllSmalldata.class);
      //      tests.add(KMeans2Test.class);
      //      tests.add(KMeans2RandomTest.class);
      //      tests.add(GLMRandomTest.Short.class);
      //      tests.add(SpeeDRFTest.class);
      //      tests.add(SpeeDRFTest2.class);
      ////      tests.add(GLMTest2.class);
      //      tests.add(DRFTest.class);
      //      tests.add(DRFTest2.class);
      //      tests.add(GBMTest.class);
      //      tests.add(KMeans2Test.class);
      //      tests.add(PCATest.class);
      //      tests.add(NetworkTestTest.class);

      // Uncomment this to sleep here and use the browser.
      // try { Thread.sleep(10000000); } catch (Exception _) {}

      JUnitCore junit = new JUnitCore();
      junit.addListener(new LogListener());
      Result result = junit.run(tests.toArray(new Class[0]));
      if (result.getFailures().size() == 0) {
        Log.info("SUCCESS!");
        System.exit(0);
      } else {
        Log.info("FAIL!");
        System.exit(1);
      }
    }
예제 #22
0
 /**
  * Run all the tests contained in <code>request</code>.
  *
  * <p>This variant should be used if {@code core} has attached listeners that this run should
  * notify.
  *
  * @param request the request describing tests
  * @param core a JUnitCore to delegate to.
  * @return a {@link Result} describing the details of the test run and the failed tests.
  */
 public Result run(Request request, JUnitCore core) {
   core.addListener(fHistory.listener());
   return core.run(sortRequest(request).getRunner());
 }