Java 类org.junit.runner.JUnitCore 实例源码

项目:CodeU-Summer-2017    文件:TestRunner.java   
public static void main(String[] args) {
  final Result result =
      JUnitCore.runClasses(
          codeu.chat.common.SecretTest.class,
          codeu.chat.relay.ServerTest.class,
          codeu.chat.server.BasicControllerTest.class,
          codeu.chat.server.RawControllerTest.class,
          codeu.chat.util.TimeTest.class,
          codeu.chat.util.TokenizerTest.class,
          codeu.chat.util.UuidTest.class,
          codeu.chat.util.store.StoreTest.class
      );
   for (final Failure failure : result.getFailures()) {
      System.out.println(failure.toString());
   }
   System.out.println(result.wasSuccessful());
}
项目:bayou    文件:TestSuiteRunner.java   
/**
 * Creates and runs a JUnit test runner for testSuite.
 *
 * @param testSuite the class defining test cases to run
 * @param view a UI component to report test failures to
 * @return the counts of failures and total test cases.
 */
static RunResult runTestSuiteAgainst(Class testSuite, View view)
{
    if(testSuite == null)
        throw new NullPointerException("testSuite");

    if(view == null)
        throw new NullPointerException("view");

    Result result = new JUnitCore().run(testSuite);

    if (result.getFailureCount() > 0)
    {
        for (Failure f : result.getFailures())
            view.declarePassProgramTestFailure(f.getTrace());
    }


    return new RunResult(result.getFailureCount(), result.getRunCount());
}
项目:codeu_project_2017    文件:TestRunner.java   
public static void main(String[] args) {
  final Result result =
      JUnitCore.runClasses(
          codeu.chat.common.SecretTest.class,
          codeu.chat.relay.ServerTest.class,
          codeu.chat.server.BasicControllerTest.class,
          codeu.chat.server.RawControllerTest.class,
          codeu.chat.util.TimeTest.class,
          codeu.chat.util.UuidTest.class,
          codeu.chat.util.store.StoreTest.class
      );
   for (final Failure failure : result.getFailures()) {
      System.out.println(failure.toString());
   }
   System.out.println(result.wasSuccessful());
}
项目:personium-core    文件:SingleJUnitTestRunner.java   
/**
 * .
 * @param args .
 * @throws ClassNotFoundException .
 */
public static void main(String... args) throws ClassNotFoundException {
    int retCode = 0;
    String resultMessage = "SUCCESS";
    String[] classAndMethod = args[0].split("#");
    Request request = Request.method(Class.forName(classAndMethod[0]),
            classAndMethod[1]);

    Result result = new JUnitCore().run(request);
    if (!result.wasSuccessful()) {
        retCode = 1;
        resultMessage = "FAILURE";
    }
    System.out.println(resultMessage);
    System.exit(retCode);
}
项目:ComputerScienceGraduation    文件:Principal.java   
/**
 * Chama o motor de testes JUnit.
 */
private static void executarTodosOs50Testes()
{
   final Result result = JUnitCore.runClasses( GrafoTest.class );
   final StringBuilder mensagem = new StringBuilder();
   if( result.getFailureCount() > 0 )
   {
      mensagem.append( "############## OS SEGUINTES TESTES FALHARAM!! "
               + "#####################################\n" );
   } else
   {
      mensagem.append( "############## TODOS OS TESTES FORAM EXECUTADOS "
               + "COM SUCESSO!! #######################\n" );
   }

   for( final Failure failure: result.getFailures() )
   {
      mensagem.append( failure.getDescription() ).append( '\n' );
      mensagem.append( failure.getMessage() ).append( '\n' );
   }
   System.out.println( mensagem );
}
项目:spring4-understanding    文件:JUnitTestingUtils.java   
/**
 * Run the tests in the supplied {@code testClass}, using the specified
 * {@link Runner}, and assert the expectations of the test execution.
 *
 * <p>If the specified {@code runnerClass} is {@code null}, the tests
 * will be run with the runner that the test class is configured with
 * (i.e., via {@link RunWith @RunWith}) or the default JUnit runner.
 *
 * @param runnerClass the explicit runner class to use or {@code null}
 * if the implicit runner should be used
 * @param testClass the test class to run with JUnit
 * @param expectedStartedCount the expected number of tests that started
 * @param expectedFailedCount the expected number of tests that failed
 * @param expectedFinishedCount the expected number of tests that finished
 * @param expectedIgnoredCount the expected number of tests that were ignored
 * @param expectedAssumptionFailedCount the expected number of tests that
 * resulted in a failed assumption
 */
public static void runTestsAndAssertCounters(Class<? extends Runner> runnerClass, Class<?> testClass,
        int expectedStartedCount, int expectedFailedCount, int expectedFinishedCount, int expectedIgnoredCount,
        int expectedAssumptionFailedCount) throws Exception {

    TrackingRunListener listener = new TrackingRunListener();

    if (runnerClass != null) {
        Constructor<?> constructor = runnerClass.getConstructor(Class.class);
        Runner runner = (Runner) BeanUtils.instantiateClass(constructor, testClass);
        RunNotifier notifier = new RunNotifier();
        notifier.addListener(listener);
        runner.run(notifier);
    }
    else {
        JUnitCore junit = new JUnitCore();
        junit.addListener(listener);
        junit.run(testClass);
    }

    assertEquals("tests started for [" + testClass + "]:", expectedStartedCount, listener.getTestStartedCount());
    assertEquals("tests failed for [" + testClass + "]:", expectedFailedCount, listener.getTestFailureCount());
    assertEquals("tests finished for [" + testClass + "]:", expectedFinishedCount, listener.getTestFinishedCount());
    assertEquals("tests ignored for [" + testClass + "]:", expectedIgnoredCount, listener.getTestIgnoredCount());
    assertEquals("failed assumptions for [" + testClass + "]:", expectedAssumptionFailedCount, listener.getTestAssumptionFailureCount());
}
项目:spring4-understanding    文件:ContextHierarchyDirtiesContextTests.java   
private void runTestAndVerifyHierarchies(Class<? extends FooTestCase> testClass, boolean isFooContextActive,
        boolean isBarContextActive, boolean isBazContextActive) {

    JUnitCore jUnitCore = new JUnitCore();
    Result result = jUnitCore.run(testClass);
    assertTrue("all tests passed", result.wasSuccessful());

    assertThat(ContextHierarchyDirtiesContextTests.context, notNullValue());

    ConfigurableApplicationContext bazContext = (ConfigurableApplicationContext) ContextHierarchyDirtiesContextTests.context;
    assertEquals("baz", ContextHierarchyDirtiesContextTests.baz);
    assertThat("bazContext#isActive()", bazContext.isActive(), is(isBazContextActive));

    ConfigurableApplicationContext barContext = (ConfigurableApplicationContext) bazContext.getParent();
    assertThat(barContext, notNullValue());
    assertEquals("bar", ContextHierarchyDirtiesContextTests.bar);
    assertThat("barContext#isActive()", barContext.isActive(), is(isBarContextActive));

    ConfigurableApplicationContext fooContext = (ConfigurableApplicationContext) barContext.getParent();
    assertThat(fooContext, notNullValue());
    assertEquals("foo", ContextHierarchyDirtiesContextTests.foo);
    assertThat("fooContext#isActive()", fooContext.isActive(), is(isFooContextActive));
}
项目:reactor    文件:CaseRunnerJUnit4.java   
@Override
public void runTaskCase() throws Exception {
    AbstractCaseData.setCaseData(null);
    String caseDataInfo = this.tcr.getTaskCase().getCaseDataInfo();
    if (!caseDataInfo.isEmpty()) {
        CaseData caseData = AbstractCaseData.getCaseData(caseDataInfo);
        LOG.debug("Injecting case data: {} = {}", caseDataInfo, caseData.getValue());
        AbstractCaseData.setCaseData(caseData);
    }

    TaskCase tc = this.tcr.getTaskCase();
    LOG.debug("Loading case {}", tc.format());
    CaseRunListener trl = new CaseRunListener(this.db, this.tcr);
    JUnitCore core = new JUnitCore();
    core.addListener(trl);
    core.run(Request.method(Class.forName(tc.getCaseClass()), tc.getCaseMethod()));
}
项目:aspectj-junit-runner    文件:JUnitLifeCycleTest.java   
@Test
public void run() {
    JUnitCore junitCore = new JUnitCore();
    Result result = junitCore.run(TestDummy.class);
    List<Failure>failures = result.getFailures();
    if(!(failures == null || failures.isEmpty())) {
        for(Failure f : failures) {
            System.out.println(f.getMessage());
        }
    }
    Assert.assertEquals(2, result.getRunCount());
    Assert.assertEquals(0, result.getIgnoreCount());
    Assert.assertEquals(0, result.getFailureCount());
    Assert.assertEquals("After was not executed", "true", System.getProperty("JUnit_After"));
    Assert.assertEquals("AfterClass was not executed", "true", System.getProperty("JUnit_AfterClass"));
}
项目:openjfx-8u-dev-tests    文件:PluginValidatorApp.java   
@Override
public void start(Stage stage) throws Exception {
    AppLauncher.getInstance().setRemoteStage(stage);

    new Thread(new Runnable() {
        public void run() {
            try {
                System.out.println("Running junit");
                Result r = new JUnitCore().run(Request.method(Class.forName(className), testName));
                System.out.println("got result = " + r.wasSuccessful());
            }
            catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            } finally {
                //System.exit(0);
            }
        }
    }).start();
}
项目:JEmAS    文件:EmotionAnalyzer_UI.java   
private static void runTests(){
    JUnitCore junit = new JUnitCore();
    Result result = junit.run(Tests.class);
    System.err.println("Ran " + result.getRunCount() + " tests in "+ result.getRunTime() +"ms.");
    if (result.wasSuccessful()) System.out.println("All tests were successfull!");
    else {
        System.err.println(result.getFailureCount() + "Failures:");
        for (Failure fail: result.getFailures()){
            System.err.println("Failure in: "+ fail.getTestHeader());
            System.err.println(fail.getMessage());
            System.err.println(fail.getTrace());
            System.err.println();
        }
    }

}
项目:SilverKing    文件:SkfsRenameGlenn.java   
public static void main(String[] args) {
    if (args.length != 1) {
        System.out.println("Need an argument for target directory: i.e. /var/tmp/silverking_holstben/skfs/skfs_mnt/skfs");
        return;
    }

    targetDirPath = args[0];
    absTestsDir   = targetDirPath + sep + testsDirName;

    targetDir = new File(targetDirPath);
    testsDir  = new File(targetDirPath, testsDirName);

    parentFile       = new File(absTestsDir, parentFileName);
    parentFileRename = new File(absTestsDir, parentFileName+"Rename");

    Result result = JUnitCore.runClasses(SkfsRenameGlenn.class);
    printSummary(result);
}
项目:SilverKing    文件:SkfsCopyGlenn.java   
public static void main(String[] args) {
    if (args.length != 1) {
        System.out.println("Need an argument for target directory: i.e. /var/tmp/silverking_holstben/skfs/skfs_mnt/skfs");
        return;
    }

    targetDirPath = args[0];
    absTestsDir   = targetDirPath + sep + testsDirName;

    targetDir = new File(targetDirPath);
    testsDir  = new File(targetDirPath, testsDirName);

    parentDir = new File(absTestsDir, parentDirName);

    Result result = JUnitCore.runClasses(SkfsCopyGlenn.class);
    printSummary(result);
    System.out.println("exists: " + exists);
}
项目:test-analyzer    文件:PresentationTest.java   
@Test
public void testTextResultPresentation() throws Exception {
    IResultPresentation presentation = new TextResultPresentation();

    final String genericExpected = "" + "Testcase: junit.framework.TestCase.test()" + NEW_LINE
            + "Mutated method: java.lang.Object.hashCode()" + NEW_LINE + "Return value generator: "
            + SAMPLE_RET_VAL_GEN_NAME + NEW_LINE + "Result: %s" + NEW_LINE + ".";

    String output;
    String expected;
    Result result;

    result = new Result();
    output = presentation.formatTestResultEntry(SAMPLE_TEST_IDENTIFIER, new JUnitTestRunResult(result),
            SAMPLE_METHOD_IDENTIFIER, SAMPLE_RET_VAL_GEN_NAME);
    expected = String.format(genericExpected, "OK");
    assertEquals(expected, output);

    result = new JUnitCore().run(Request.method(SampleJUnitTestClass.class, "b"));
    output = presentation.formatTestResultEntry(SAMPLE_TEST_IDENTIFIER, new JUnitTestRunResult(result),
            SAMPLE_METHOD_IDENTIFIER, SAMPLE_RET_VAL_GEN_NAME);
    expected = String.format(genericExpected, "1 of 1 FAILED" + NEW_LINE + "Exception: java.lang.AssertionError");
    assertEquals(expected, output);
}
项目:test-analyzer    文件:PresentationTest.java   
@Test
public void testDatabaseResultPresentation() {
    IResultPresentation presentation = new DatabaseResultPresentation();
    presentation.setExecutionId(ExecutionIdFactory.parseShortExecutionId("EXEC"));

    final String genericExpected = "INSERT INTO Test_Result_Import (execution, testcase, method, retValGen, killed, assertErr, exception) VALUES ('EXEC', 'junit.framework.TestCase.test()', 'java.lang.Object.hashCode()', '%s', %s, %s, '%s');";

    String output;
    String expected;
    Result result;

    result = new Result();
    output = presentation.formatTestResultEntry(SAMPLE_TEST_IDENTIFIER, new JUnitTestRunResult(result),
            SAMPLE_METHOD_IDENTIFIER, SAMPLE_RET_VAL_GEN_NAME);
    expected = String.format(genericExpected, SAMPLE_RET_VAL_GEN_NAME, false, false, "");
    assertEquals(expected, output);

    result = new JUnitCore().run(Request.method(SampleJUnitTestClass.class, "b"));
    output = presentation.formatTestResultEntry(SAMPLE_TEST_IDENTIFIER, new JUnitTestRunResult(result),
            SAMPLE_METHOD_IDENTIFIER, SAMPLE_RET_VAL_GEN_NAME);
    expected = String.format(genericExpected, SAMPLE_RET_VAL_GEN_NAME, true, true, AssertionError.class.getName());
    assertEquals(expected, output);
}
项目:peloton-test    文件:JUnitRunner.java   
public void runTests(String outputDir) {
    JUnitCore junit = new JUnitCore();
    if (outputDir == null) {
        junit.addListener(new TextListener(System.out));
    } else {
        junit.addListener(new JUnitResultFormatterAsRunListener(new XMLJUnitResultFormatter()) {
            @Override
            public void testStarted(Description description) throws Exception {
                formatter.setOutput(new FileOutputStream(
                        new File(outputDir, "TEST-" + description.getDisplayName() + ".xml")));
                super.testStarted(description);
            }
        });
    }
    junit.run(TestContainer.class);
}
项目:junit-composite-runner    文件:CompositeRunnerTest.java   
@Test
public void testSystem() throws Throwable {
    Computer computer = new Computer();
    JUnitCore jUnitCore = new JUnitCore();

    ByteArrayOutputStream capture = new ByteArrayOutputStream();
    final PrintStream printStream = new PrintStream(capture);
    TextListener listener = new TextListener(printStream);
    jUnitCore.addListener(listener);

    PrintStream systemOut = System.out;
    System.setOut(printStream);
    try {
        jUnitCore.run(computer, ExampleTest.class);
    } finally {
        System.setOut(systemOut);
    }

    String output = capture.toString("UTF-8");
    output = normalizeOutput(output);

    String expectedOutput = getResource("/CompositeTest.testSystem.expected.txt");
    Assert.assertEquals(expectedOutput, output);
}
项目:Informatique-1    文件:EXQ2Corr.java   
public static void main(String[] args) {

        Result result = JUnitCore.runClasses(EXQ2Tests.class);
        Iterator<Failure> failures = result.getFailures().iterator();
        Failure f;
        while(failures.hasNext()){
            f = failures.next();
            System.err.println(f.getMessage());
            //System.err.println(f.getTrace());
        }
        if(result.wasSuccessful() == true){
            System.out.println(true);
            /**127 : nombre magique afin de signaler que tout les tests sont passés */
            System.exit(127);
        }
    }
项目:kc-rice    文件:LoadTimeWeavableTestRunner.java   
protected boolean runBootstrapTest(RunNotifier notifier, TestClass testClass) {
    if (!runningBootstrapTest.get().booleanValue()) {
        runningBootstrapTest.set(Boolean.TRUE);
        try {
            BootstrapTest bootstrapTest = getBootstrapTestAnnotation(testClass.getJavaClass());
            if (bootstrapTest != null) {
                Result result = JUnitCore.runClasses(bootstrapTest.value());
                List<Failure> failures = result.getFailures();
                for (Failure failure : failures) {
                    notifier.fireTestFailure(failure);
                }
                return result.getFailureCount() == 0;
            } else {
                throw new IllegalStateException("LoadTimeWeavableTestRunner, must be coupled with an @BootstrapTest annotation to define the bootstrap test to execute.");
            }
        } finally {
            runningBootstrapTest.set(Boolean.FALSE);
        }
    }
    return true;
}
项目:Informatique-1    文件:EXQ6Vide.java   
public static void main(String[] args) {

        Result result = JUnitCore.runClasses(EXQ6Tests.class);
        Iterator<Failure> failures = result.getFailures().iterator();
        Failure f;
        while(failures.hasNext()){
            f = failures.next();
            System.err.println(f.getMessage());
            //System.err.println(f.getTrace());
        }
        if(result.wasSuccessful() == true){
            //System.out.println(true);
            /**127 : nombre magique afin de signaler que tout les tests sont passés */
            System.exit(127);
        }
    }
项目:VoltDB    文件:VoltTestRunner.java   
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();
    }
}
项目:squidb    文件:SquidbTestRunner.java   
/**
 * 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, PrintStream out) {
    JUnitCore junitCore = new JUnitCore();
    junitCore.addListener(listener);
    boolean hasError = false;
    int numTests = 0;
    int numFailures = 0;
    long start = System.currentTimeMillis();
    for (@AutoreleasePool Class c : classes) {
        out.println("Running " + c.getName());
        Result result = junitCore.run(c);
        numTests += result.getRunCount();
        numFailures += result.getFailureCount();
        hasError = hasError || !result.wasSuccessful();
    }
    long end = System.currentTimeMillis();
    out.println(String.format("Ran %d tests, %d failures. Total time: %s seconds", numTests, numFailures,
            NumberFormat.getInstance().format((double) (end - start) / 1000)));
    return hasError ? 1 : 0;
}
项目:fhaes    文件:UnitTestRunner.java   
/**
 * Runs all unit tests defined in the FHAES test suite.
 */
@Test
public void runUnitTests() {

    Result result = JUnitCore.runClasses(FHAESTestSuite.class);

    if (result.getFailureCount() > 0)
    {
        for (Failure failure : result.getFailures())
        {
            log.error(failure.getException().toString());
            log.error("error occurred in: " + failure.getTestHeader());

            // Report to the JUnit window that a failure has been encountered
            Assert.fail(failure.getTrace());
        }
    }
    else
    {
        log.info("All tests passed for FHAESTestSuite");
    }
}
项目:cuppa    文件:CuppaRunnerTest.java   
@Test
public void shouldReportDescriptionsinCorrectOrder() {
    JUnitCore jUnit = new JUnitCore();
    jUnit.addListener(new RunListener() {
        @Override
        public void testRunStarted(Description description) throws Exception {
            suiteDescription = description;
        }
    });
    jUnit.run(CuppaRunnerTest.TestsAndTestBlocks.class);

    List<Description> rootDescriptionChildren = suiteDescription
            .getChildren().get(0).getChildren().get(0).getChildren();
    assertThat(rootDescriptionChildren).hasSize(3);
    assertThat(rootDescriptionChildren.get(0).getDisplayName()).startsWith("a");
    assertThat(rootDescriptionChildren.get(1).getDisplayName()).startsWith("b");
    assertThat(rootDescriptionChildren.get(2).getDisplayName()).startsWith("when c");
    assertThat(rootDescriptionChildren.get(2).getChildren().get(0).getDisplayName()).startsWith("d");
}
项目:Informatique-1    文件:M11Q7Corr.java   
public static void main(String[] args) {

        Result result = JUnitCore.runClasses(DListTest.class);
        Iterator<Failure> failures = result.getFailures().iterator();
        Failure f;
        while(failures.hasNext()){
            f = failures.next();
            System.err.println(f.getMessage());
            //System.err.println(f.getTrace());
        }
        if(result.wasSuccessful() == true){
            System.out.println(true);
            /**127 : nombre magique afin de signaler que tout le tests sont passés */
            System.exit(127);
        }
    }
项目:Informatique-1    文件:M11Q7Vide.java   
public static void main(String[] args) {

        Result result1 = JUnitCore.runClasses(DListTest.class);
        Result result2 = JUnitCore.runClasses(DListParseTest.class);
        Iterator<Failure> failures1 = result1.getFailures().iterator();
        Failure f;
        while(failures1.hasNext()){
            f = failures1.next();
            System.err.println(f.getMessage());
            //System.err.println(f.getTrace());
        }
        Iterator<Failure> failures2 = result2.getFailures().iterator();
        while(failures2.hasNext()){
            f = failures2.next();
            System.err.println(f.getMessage());
            //System.err.println(f.getTrace());
        }

        if(result1.wasSuccessful() && result2.wasSuccessful()){
            //System.out.println(true);
            /**127 : nombre magique afin de signaler que tout les tests sont passés */
            System.exit(127);
        }
    }
项目:Informatique-1    文件:M11Q7Corr.java   
public static void main(String[] args) {

        Result result = JUnitCore.runClasses(DListTest.class);
        Iterator<Failure> failures = result.getFailures().iterator();
        Failure f;
        while(failures.hasNext()){
            f = failures.next();
            System.err.println(f.getMessage());
            //System.err.println(f.getTrace());
        }
        if(result.wasSuccessful() == true){
            System.out.println(true);
            /**127 : nombre magique afin de signaler que tout les tests sont passés */
            System.exit(127);
        }
    }
项目:Informatique-1    文件:M11Q7Corr.java   
public static void main(String[] args) {

        Result result = JUnitCore.runClasses(DListTest.class);
        Iterator<Failure> failures = result.getFailures().iterator();
        Failure f;
        while(failures.hasNext()){
            f = failures.next();
            System.err.println(f.getMessage());
            //System.err.println(f.getTrace());
        }
        if(result.wasSuccessful() == true){
            System.out.println(true);
            /**127 : nombre magique afin de signaler que tout le tests sont passés */
            System.exit(127);
        }
    }
项目:Informatique-1    文件:EXQ6Corr.java   
public static void main(String[] args) {

        Result result = JUnitCore.runClasses(EXQ6Tests.class);
        Iterator<Failure> failures = result.getFailures().iterator();
        Failure f;
        while(failures.hasNext()){
            f = failures.next();
            System.err.println(f.getMessage());
            //System.err.println(f.getTrace());
        }
        if(result.wasSuccessful() == true){
            System.out.println(true);
            /**127 : nombre magique afin de signaler que tout les tests sont passés */
            System.exit(127);
        }
    }
项目:Informatique-1    文件:EXQ6Vide.java   
public static void main(String[] args) {

        Result result = JUnitCore.runClasses(EXQ6Tests.class);
        Iterator<Failure> failures = result.getFailures().iterator();
        Failure f;
        while(failures.hasNext()){
            f = failures.next();
            System.err.println(f.getMessage());
            //System.err.println(f.getTrace());
        }
        if(result.wasSuccessful() == true){
            //System.out.println(true);
            /**127 : nombre magique afin de signaler que tout les tests sont passés */
            System.exit(127);
        }
    }
项目:Informatique-1    文件:M11Q7Corr.java   
public static void main(String[] args) {

        Result result = JUnitCore.runClasses(DListTest.class);
        Iterator<Failure> failures = result.getFailures().iterator();
        Failure f;
        while(failures.hasNext()){
            f = failures.next();
            System.err.println(f.getMessage());
            //System.err.println(f.getTrace());
        }
        if(result.wasSuccessful() == true){
            System.out.println(true);
            /**127 : nombre magique afin de signaler que tout les tests sont passés */
            System.exit(127);
        }
    }
项目:Informatique-1    文件:M5Q5.java   
public static void main(String[] args) {

        Result result = JUnitCore.runClasses(M5Q5TestSuite.class);
        Iterator<Failure> failures = result.getFailures().iterator();
        Failure f;
        while(failures.hasNext()){
            f = failures.next();
            System.err.println(f.getMessage());
            System.err.println(f.getException());

        }
        if(result.wasSuccessful() == true){
            /**127 : nombre magique afin de signaler que tout le tests sont passés */
            System.exit(127);

        }

    }
项目:android-groovy-dagger-espresso-demo    文件:AndroidSpockRunner.java   
private void addListeners(List<RunListener> listeners, JUnitCore testRunner,
                          PrintStream writer) {
    if (getBooleanArgument(ARGUMENT_SUITE_ASSIGNMENT)) {
        listeners.add(new SuiteAssignmentPrinter());
    } else {
        listeners.add(new TextListener(writer));
        listeners.add(new LogRunListener());
        mInstrumentationResultPrinter = new InstrumentationResultPrinter();
        listeners.add(mInstrumentationResultPrinter);
        listeners.add(new ActivityFinisherRunListener(this,
                new ActivityFinisher()));
        addDelayListener(listeners);
        addCoverageListener(listeners);
    }

    addListenersFromArg(listeners, writer);
    addListenersFromManifest(listeners, writer);

    for (RunListener listener : listeners) {
        testRunner.addListener(listener);
        if (listener instanceof InstrumentationRunListener) {
            ((InstrumentationRunListener) listener).setInstrumentation(this);
        }
    }
}
项目:AugmentedDriver    文件:TestRunner.java   
/**
 * Wrapper over JUniteCore that runs one test.
 *
 * @return the result of the test.
 * @throws Exception if there was an exception running the test.
 */
@Override
public AugmentedResult call() throws Exception {
    JUnitCore jUnitCore = getJUnitCore();
    String testName = String.format("%s#%s", test.getDeclaringClass().getCanonicalName(), test.getName());
    long start = System.currentTimeMillis();
    try {
        LOG.info(String.format("STARTING Test %s", testName));
        // HACK since for TestSuiteRunner we want to retry, and for TestMethodRunner we don't want to
        // The other way would be a RETRY on augmented.properties, but this is independent of the configuration of
        // the test.
        if (retry) {
            TestRunnerRetryingRule.retry();
        }
        Result result = jUnitCore.run(Request.method(test.getDeclaringClass(), test.getName()));
        LOG.info(String.format("FINSHED Test %s in %s, result %s", testName,
                Util.TO_PRETTY_FORMAT.apply(System.currentTimeMillis() - start), result.wasSuccessful()? "SUCCEEDED" : "FAILED"));
        return new AugmentedResult(testName, result, outputStream);
    } finally {
        outputStream.close();
    }
}
项目:Informatique-1    文件:EXQ4Vide.java   
public static void main(String[] args) {

        Result result = JUnitCore.runClasses(EXQ4Tests.class);
        Iterator<Failure> failures = result.getFailures().iterator();
        Failure f;
        while(failures.hasNext()){
            f = failures.next();
            System.err.println(f.getMessage());
            //System.err.println(f.getTrace());
        }
        if(result.wasSuccessful() == true){
            //System.out.println(true);
            /**127 : nombre magique afin de signaler que tout les tests sont passés */
            System.exit(127);
        }
    }
项目:GitHub    文件:Bug_for_Next.java   
public static void main(String[] args) throws Exception {
    Result result = JUnitCore.runClasses(Bug_for_Next.class);
    for (Failure fail : result.getFailures()) {
        System.out.println(fail.toString());
    }
    if (result.wasSuccessful()) {
        System.out.println("All tests finished successfully...");
    }
}
项目:CodeU-ProjectGroup6    文件:TestRunner.java   
public static void main(String[] args) {
  final Result result =
      JUnitCore.runClasses(
          codeu.chat.common.SecretTest.class,
          codeu.chat.relay.ServerTest.class,
          codeu.chat.server.BasicControllerTest.class,
          codeu.chat.server.RawControllerTest.class,
          codeu.chat.util.TimeTest.class,
          codeu.chat.util.UuidTest.class,
          codeu.chat.util.store.StoreTest.class,
          codeu.chat.util.TokenizerTest.class,
          codeu.chat.server.ControllerTest.class
      );

   System.out.println("\n===================== Test Status ====================");
   System.out.println(String.format("%d tests run.", result.getRunCount()));

   if (result.wasSuccessful()) {
     System.out.println("All tests passed.");
   } else {
     System.out.println(String.format("%d tests failed.", result.getFailureCount()));
     System.out.println("\nFailures:");
     for (final Failure failure : result.getFailures()) {
        System.out.println(failure.toString());
     }
   }

   System.out.println("======================================================\n");
   System.exit(result.wasSuccessful() ? 0 : -1);
}
项目:lambda-selenium    文件:LambdaTestHandler.java   
public TestResult handleRequest(TestRequest testRequest, Context context) {
    LoggerContainer.LOGGER = new Logger(context.getLogger());
    System.setProperty("target.test.uuid", testRequest.getTestRunUUID());

    Optional<Result> result = Optional.empty();
    try {
        BlockJUnit4ClassRunner runner = new BlockJUnit4ClassRunner(getTestClass(testRequest));
        runner.filter(new MethodFilter(testRequest.getFrameworkMethod()));

        result = ofNullable(new JUnitCore().run(runner));
    } catch (Exception e) {
        testResult.setThrowable(e);
        LOGGER.log(e);
    }

    if (result.isPresent()) {
        testResult.setRunCount(result.get().getRunCount());
        testResult.setRunTime(result.get().getRunTime());
        LOGGER.log("Run count: " + result.get().getRunCount());
        result.get().getFailures().forEach(failure -> {
            LOGGER.log(failure.getException());
            testResult.setThrowable(failure.getException());
        });
    }

    return testResult;
}
项目:shabdiz    文件:JUnitBootstrapCore.java   
@Override
protected void deploy(final String... args) throws Exception {

    configure(args);
    final JUnitCore core = new JUnitCore();
    final Result result = core.run(test_classes.toArray(new Class[test_classes.size()]));
    for (Failure failure : failures) {
        result.getFailures().add(failure);
    }

    setProperty(TEST_RESULT, serializeAsBase64(result));
}
项目:sunshine    文件:Junit4Kernel.java   
/**
 * Returns new instance of the JUnit kernel with provided listeners.
 *
 * @param listeners an instance (or instances) of JUnit listeners
 * @return the new instance of the JUnit kernel
 */
@Override
public Junit4Kernel with(RunListener... listeners) {
    final JUnitCore jUnitCore = new JUnitCore();
    Arrays.stream(listeners).forEach(jUnitCore::addListener);
    return new Junit4Kernel(jUnitCore, this.suiteForRun);
}