public Result doRun(Test suite, boolean wait) { MarathonTestRunner runner = new MarathonTestRunner(); runReportDir = argProcessor.getReportDir(); String resultsDir = new File(runReportDir, "results").getAbsolutePath(); if (runReportDir != null) { System.setProperty(Constants.PROP_REPORT_DIR, runReportDir); System.setProperty(Constants.PROP_IMAGE_CAPTURE_DIR, runReportDir); System.setProperty("allure.results.directory", resultsDir); runner.addListener(new AllureMarathonRunListener()); } runner.addListener(new TextListener(System.out)); Result result = runSuite(suite, runner); MarathonTestCase.reset(); if (runReportDir != null && !argProcessor.isSkipreports()) { AllureUtils.launchAllure(false, resultsDir, new File(runReportDir, "reports").getAbsolutePath()); } return result; }
@Test public void firstShouldBeFirstBeforeLastAfter() { Result result = TestRunner.runTest(ThreeRules.class); assertThat(result.wasSuccessful()).isTrue(); assertThat(counter.get()).isEqualTo(9); assertThat(invocations[0].beforeInvocation).isEqualTo(1); assertThat(invocations[1].beforeInvocation).isEqualTo(2); assertThat(invocations[2].beforeInvocation).isEqualTo(3); assertThat(invocations[0].testInvocation).isEqualTo(4); assertThat(invocations[1].testInvocation).isEqualTo(5); assertThat(invocations[2].testInvocation).isEqualTo(6); assertThat(invocations[2].afterInvocation).isEqualTo(7); assertThat(invocations[1].afterInvocation).isEqualTo(8); assertThat(invocations[0].afterInvocation).isEqualTo(9); }
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()); }
/** * * @see org.junit.runner.notification.RunListener#testRunFinished(org.junit.runner.Result) */ @Override public void testRunFinished( Result result ) throws Exception { if (log.isDebugEnabled()) { log.debug("testRunFinished(): result " + "| failure count: " + result.getFailureCount() + "| ignored count: " + result.getIgnoreCount() + "| tests run count: " + result.getRunCount() + "| Run time: " + result.getRunTime() + "ms."); } if (lastSuiteName != null) { logger.endSuite(); lastSuiteName = null; // Run finished. A lastSuiteName should not be visible between runs } // end the run logger.endRun(); super.testRunFinished(result); }
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()); }
/** * 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()); }
/** * . * @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); }
@Test public void failsWithExpectedTimeoutButWrongError() { Result result = TestRunner.runTest(FailsWithExpectedTimeoutButWrongError.class); assertThat(result.wasSuccessful()).isFalse(); List<Failure> failures = result.getFailures(); assertThat(failures.size()).as("Failures: " + failures).isEqualTo(1); Failure failure = failures.get(0); String expectedMessage = "\n" + "Expected: (an instance of java.util.concurrent.TimeoutException and exception with message a string containing \"this is a message for FailsWithExpectedTimeoutButWrongError\")" + "\n" + " " + "but: an instance of java.util.concurrent.TimeoutException <java.lang.NullPointerException> is a java.lang.NullPointerException"; assertThat(failure.getException()).isExactlyInstanceOf(AssertionError.class) .hasMessageContaining(expectedMessage); }
/** * Checks that result has no failures. * Print all the failures in error message if there are any. */ public static void assertResultHasNoFailures(Result result) { List<Failure> failures = result.getFailures(); assertThat(failures) .as("No failures expected. Failures: %s", failures.stream() .map(ResultAssertions::formFailureDescription) .collect(Collectors.toList())) .isEmpty(); }
@Test public void testBrokenCategoryAndParameterized() { Request request = Request.aClass(BrokenCategoryClass.class); ExposedParameterized runner = (ExposedParameterized) request.getRunner(); request = request.filterWith(new CategoryFilter( (ExposedBlockJUnit4ClassRunnerWithParameters) runner.getChildren().get(0))); Result result = new JUnitCore().run(request); assertEquals( "Yeah!! This might actually mean we've upgraded to JUnit 4.13. Hurry up already and delete this hack.", 1, result.getRunCount()); }
@Test public void failsOnSecondAttempt() { Result result = TestRunner.runTest(FailsOnSecondAttempt.class); assertThat(result.wasSuccessful()).isFalse(); List<Failure> failures = result.getFailures(); assertThat(failures.size()).as("Failures: " + failures).isEqualTo(1); Failure failure = failures.get(0); assertThat(failure.getException()).isExactlyInstanceOf(CustomException.class) .hasMessage(FailsOnSecondAttempt.message); assertThat(FailsOnSecondAttempt.count).isEqualTo(2); }
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..."); } }
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); }
@Test public void failingTestShouldFailOneTimeWhenRepeatIsThree() { Result result = TestRunner.runTest(FailingTestShouldFailOneTimeWhenRepeatIsThree.class); assertThat(result.wasSuccessful()).isFalse(); List<Failure> failures = result.getFailures(); assertThat(failures.size()).as("Failures: " + failures).isEqualTo(1); Failure failure = failures.get(0); assertThat(failure.getException()).isExactlyInstanceOf(AssertionError.class) .hasMessage(ASSERTION_ERROR_MESSAGE); assertThat(FailingTestShouldFailOneTimeWhenRepeatIsThree.count).isEqualTo(1); }
@Test public void passesOnThirdAttempt() { Result result = TestRunner.runTest(PassesOnThirdAttempt.class); assertThat(result.wasSuccessful()).isTrue(); assertThat(PassesOnThirdAttempt.count).isEqualTo(3); }
/** * Run Marathon in batch mode. */ private static void runBatchMode() { String projectDir = argProcessor.getProjectDirectory(); if (projectDir == null) { argProcessor.help("No project directory"); return; } if (!ProjectFile.isValidProjectDirectory(new File(projectDir))) { argProcessor.help("`" + projectDir + "` is an invalid project folder. Please provide a valid Marathon project folder."); return; } if (projectDir.endsWith(".mpf") && new File(projectDir).isFile()) { argProcessor.help("A marathon project file is given.\nUse project directory instead"); return; } processMPF(projectDir, true); OSUtils.setLogConfiguration(projectDir); RuntimeLogger.setRuntimeLogger(new NullLogger()); cleanResultFolder(); TestRunner aTestRunner = createTestRunner(); try { Result r = aTestRunner.runTests(argProcessor); if (!r.wasSuccessful()) { System.exit(junit.textui.TestRunner.FAILURE_EXIT); } System.exit(junit.textui.TestRunner.SUCCESS_EXIT); } catch (Exception e) { LOGGER.severe(e.getMessage()); System.exit(junit.textui.TestRunner.EXCEPTION_EXIT); } }
private static Result runInnerTest(Class innerClass) { EVENTS.put(innerClass, FastList.<String>newList()); File ouputFile = new File(TableTestUtils.getOutputDirectory(), innerClass.getSimpleName() + ".html"); if (ouputFile.exists()) { Assert.assertTrue("Deleting " + ouputFile, ouputFile.delete()); } return new JUnitCore().run(innerClass); }
@Test public void allTestsWithCategoryOneShouldBeExecuted() { Result result = TestRunner.runTest(CategoryTestSuite.class); assertThat(result.wasSuccessful()).isTrue(); assertThat(executedClassOneMethodNone).isTrue(); assertThat(executedClassOneMethodTwo).isTrue(); assertThat(executedClassTwoMethodTwo).isFalse(); assertThat(executedClassNoneMethodOne).isTrue(); assertThat(executedClassNoneMethodTwo).isFalse(); assertThat(executedClassTwoMethodOne).isTrue(); assertThat(executedClassOneMethodOne).isTrue(); assertThat(executedClassOneAndTwoMethodNone).isTrue(); assertThat(executedClassNoneMethodOneAndTwo).isTrue(); }
private void printIgnoredTestCases(final Result result) { if (result.getIgnoreCount() == 1) { printlnWarning("1 test case was ignored."); } else if (result.getIgnoreCount() > 1) { printlnWarning(result.getIgnoreCount() + " test cases were ignored."); } }
public void testCustomLevelPerMethod() throws Exception { LoggingListener loggingListener = new LoggingListener(); Description suiteDescription = Description.createSuiteDescription(TestClass.class); Logger xyzLogger = Loggers.getLogger("xyz"); Logger abcLogger = Loggers.getLogger("abc"); final Level level = ESLoggerFactory.getRootLogger().getLevel(); assertThat(xyzLogger.getLevel(), equalTo(level)); assertThat(abcLogger.getLevel(), equalTo(level)); loggingListener.testRunStarted(suiteDescription); assertThat(xyzLogger.getLevel(), equalTo(level)); assertThat(abcLogger.getLevel(), equalTo(level)); Method method = TestClass.class.getMethod("annotatedTestMethod"); TestLogging annotation = method.getAnnotation(TestLogging.class); Description testDescription = Description.createTestDescription(LoggingListenerTests.class, "annotatedTestMethod", annotation); loggingListener.testStarted(testDescription); assertThat(xyzLogger.getLevel(), equalTo(Level.TRACE)); assertThat(abcLogger.getLevel(), equalTo(level)); loggingListener.testFinished(testDescription); assertThat(xyzLogger.getLevel(), equalTo(level)); assertThat(abcLogger.getLevel(), equalTo(level)); loggingListener.testRunFinished(new Result()); assertThat(xyzLogger.getLevel(), equalTo(level)); assertThat(abcLogger.getLevel(), equalTo(level)); }
/** * Runs a single test class, adding its results to <code>globalResults</code>. * * @param globalResults A global record of test results. * @param testClass The test class to run. */ void runSingleTest(final TestResults globalResults, final Class<?> testClass) { final String className = Objects.requireNonNull(testClass).getName(); LOG.info("{}Running {}{}", ANSI_GREEN, className, ANSI_RESET); try { Result result = junitCore.run(testClass); globalResults.merge(testClass, result); } catch (Exception e) { // most likely JUnit issues, like no tests to run LOG.error("{}Test failed: {}{}", ANSI_RED, className, ANSI_RESET, e); } }
/** * Lanceur d'une seule méthode de test * * @param args * @throws ClassNotFoundException */ public static void main(String[] args) throws ClassNotFoundException { if(args.length != 2) { System.out.println("Usage : JUnit_Test class method"); } else { Request request = Request.method(Class.forName(args[0]), args[1]); Result result = new JUnitCore().run(request); System.exit(result.wasSuccessful() ? 0 : 1); } }
public static void main(String[] args) { Result result = JUnitCore.runClasses(TestVersion2.class); System.out.println(result.getFailureCount() + " tests failed out a total of " + result.getRunCount()); for(Failure failure : result.getFailures()) { System.out.println(failure.toString()); } }
@Test public void failedTest() throws Exception { Class testClass = LifecycleTestFailedInnerTest.class; Result result = runInnerTest(testClass); Assert.assertFalse(result.wasSuccessful()); Assert.assertTrue(getOutputFile(testClass).exists()); Assert.assertEquals(Arrays.asList("onStarted", "onFailed", "onFinished"), EVENTS.get(testClass)); }
@Test @DisplayName("Should not throw exception processing test from default package") public void shouldProcessTestFromDefaultPackage() throws Exception { Class<?> testInDefaultPackage = Class.forName("SampleTestInDefaultPackage"); Result result = core.run(Request.aClass(testInDefaultPackage)); assertThat(result.wasSuccessful()).isTrue(); }
public static void main(String[] args) { Result result = JUnitCore.runClasses(TestSuite.class); for (Failure failure : result.getFailures()) { System.out.println(failure.toString()); } if(result.wasSuccessful()){ System.out.println("The tests all passed: " + result.wasSuccessful()); } else System.err.println("The tests all passed: " + result.wasSuccessful()); }
/** * Méthode takeScreenShot. * @throws SaladiumException */ public String takeScreenShot() { String pathScreenShot = ""; try { String capturePath = AbstractWorker.capturePath; File scrFile = ((TakesScreenshot) this).getScreenshotAs(OutputType.FILE); FileUtil.upload(scrFile.getAbsolutePath(), capturePath + "/" + scrFile.getName()); pathScreenShot = capturePath + "/" + scrFile.getName(); this.logger.info("ScreenShot effectué" + pathScreenShot); } catch (Exception e1) { this.logger.info("takeScreenShot échoué"); e1.printStackTrace(); } // try { // // déconnexion // By decoLocator = By.cssSelector("#logoff > a"); // WebElement webElement = wait.until(ExpectedConditions.elementToBeClickable(decoLocator)); // webElement.click(); // } catch (TimeoutException e) { // Assert.fail("Tentative de forçage de déconnexion après un sreenshot échouée"); // } // A activer si vous souhaitez arrêter les tests dès le premier screenshot effectué (idéal en mode dev ou debug) RunNotifier notifier = new RunNotifier(); Result result = new Result(); RunListener listener = result.createListener(); notifier.addFirstListener(listener); notifier.pleaseStop(); return pathScreenShot; }
public static void main(String args[]) { Result r = JUnitCore.runClasses(TestLogicControllerSoup.class, TestLowLevel.class); for (Failure fail : r.getFailures()) { System.out.println(fail); } String resultFinal = String.valueOf(r.wasSuccessful()); System.out.println("Soup ran without errors: " + resultFinal.toUpperCase()); }
public static void main(String[] args) throws ClassNotFoundException { Result res = JUnitCore.runClasses(Class.forName("formatsi.FormatTest")); for (Failure fail : res.getFailures()) { System.out.println(String.format("Test failed: %s", fail.getTestHeader())); } System.out.println("Messages:"); printMessages(); }
@Test public void failsUnused() { Result result = TestRunner.runTest(FailsUnused.class); assertThat(result.wasSuccessful()).isFalse(); List<Failure> failures = result.getFailures(); assertThat(failures.size()).as("Failures: " + failures).isEqualTo(1); Failure failure = failures.get(0); assertThat(failure.getException()).isExactlyInstanceOf(CustomException.class) .hasMessage(FailsUnused.message); assertThat(FailsUnused.count).isEqualTo(1); }
@Test public void should_store_project_under_test_directory_when_test_is_passing_but_property_is_set() throws IOException { System.setProperty("test.bed.project.persist", "true"); final Result result = JUnitCore.runClasses(ProjectPersistAnotherPass.class); assertThat(result.wasSuccessful()).isTrue(); assertThat(findPersistedProjects("repo.bundle", "ProjectPersistAnotherPass_should_pass")).hasSize(1); }
@Test public void should_not_store_project_under_test_directory_when_test_is_passing() throws IOException { final Result result = JUnitCore.runClasses(ProjectPersistPass.class); assertThat(result.wasSuccessful()).isTrue(); assertThat(findPersistedProjects("repo.bundle", "ProjectPersistPass_should_pass")).isEmpty(); }
public static void main(String[] args) { Result result = JUnitCore.runClasses(BankDetailsJunitTest.class); for (Failure failure : result.getFailures()) { System.out.println(failure.toString()); } System.out.println("=========================================================================="); System.out.println(result.wasSuccessful()); }
@Test public void zeroIsIllegal() { Result result = TestRunner.runTest(ZeroIsIllegal.class); assertThat(result.wasSuccessful()).isFalse(); List<Failure> failures = result.getFailures(); assertThat(failures.size()).as("Failures: " + failures).isEqualTo(1); Failure failure = failures.get(0); assertThat(failure.getException()).isExactlyInstanceOf(IllegalArgumentException.class) .hasMessage(ZeroIsIllegal.message); assertThat(ZeroIsIllegal.count).isEqualTo(0); }
@Test public void passingTestShouldPassThreeTimesWhenRepeatIsThree() { Result result = TestRunner.runTest(PassingTestShouldPassThreeTimesWhenRepeatIsThree.class); assertThat(result.wasSuccessful()).isTrue(); assertThat(PassingTestShouldPassThreeTimesWhenRepeatIsThree.count).isEqualTo(3); }
public TestResult(Result result, double executionTime, boolean compiled, boolean patchedOK, String patchedProgram) { this.junitResult = result; this.executionTime = executionTime; this.compiled = compiled; this.patchSuccess = patchedOK; this.patchedProgram = patchedProgram; }
@Test public void missingTableTest() throws Exception { Class testClass = LifecycleTestMissingTableInnerTest.class; Result result = runInnerTest(testClass); Assert.assertFalse(result.wasSuccessful()); Assert.assertTrue(getOutputFile(testClass).exists()); Assert.assertEquals(Arrays.asList("onStarted", "onFailed", "onFinished"), EVENTS.get(testClass)); }
@Test public void zeroValueShouldThrowIllegalArgumentException() { Result result = TestRunner.runTest(ZeroValueShouldThrowIllegalArgumentException.class); assertThat(result.wasSuccessful()).isFalse(); List<Failure> failures = result.getFailures(); assertThat(failures.size()).as("Failures: " + failures).isEqualTo(1); Failure failure = failures.get(0); assertThat(failure.getException()).isExactlyInstanceOf(IllegalArgumentException.class) .hasMessage("Repeat value must be a positive integer"); assertThat(ZeroValueShouldThrowIllegalArgumentException.count).isEqualTo(0); }
@Test public void passesWithOne() { Result result = TestRunner.runTest(PassesWithOne.class); assertThat(result.wasSuccessful()).isTrue(); assertThat(PassesWithOne.count).isEqualTo(1); }