Search in sources :

Example 81 with JUnitCore

use of org.junit.runner.JUnitCore in project ddf by codice.

the class PaxExamRuleTest method validBeforeAndAfter.

@Test
public void validBeforeAndAfter() {
    JUnitCore core = new JUnitCore();
    Result result = core.run(PassingBeforeExamAndAfterExamTest.class);
    assertThat(result.getFailures()).extracting("message").contains(FAILING_TEST_MESSAGE);
    assertResultCounts(result, 1);
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Result(org.junit.runner.Result) Test(org.junit.Test)

Example 82 with JUnitCore

use of org.junit.runner.JUnitCore in project bitsquare by bitsquare.

the class StressTestMailboxMessage method main.

// # MAIN ENTRY POINT
// Inspired by <https://stackoverflow.com/a/9288513> by Marc Peters.
public static void main(String[] args) {
    Request request = (args.length == 0) ? Request.aClass(NetworkStressTest.class) : Request.method(NetworkStressTest.class, args[0]);
    Result result = new JUnitCore().run(request);
    for (Failure f : result.getFailures()) System.err.printf("\n%s\n%s", f, f.getTrace());
    System.exit(result.wasSuccessful() ? 0 : 1);
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request) Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result)

Example 83 with JUnitCore

use of org.junit.runner.JUnitCore in project sling by apache.

the class TestsManagerImpl method executeTests.

public void executeTests(Collection<String> testNames, Renderer renderer, TestSelector selector) throws Exception {
    renderer.title(2, "Running tests");
    waitForSystemStartup();
    final JUnitCore junit = new JUnitCore();
    // Create a test context if we don't have one yet
    final boolean createContext = !SlingTestContextProvider.hasContext();
    if (createContext) {
        SlingTestContextProvider.createContext();
    }
    try {
        junit.addListener(new TestContextRunListenerWrapper(renderer.getRunListener()));
        for (String className : testNames) {
            renderer.title(3, className);
            // If we have a test context, clear its output metadata
            if (SlingTestContextProvider.hasContext()) {
                SlingTestContextProvider.getContext().output().clear();
            }
            final String testMethodName = selector == null ? null : selector.getSelectedTestMethodName();
            if (testMethodName != null && testMethodName.length() > 0) {
                log.debug("Running test method {} from test class {}", testMethodName, className);
                junit.run(Request.method(getTestClass(className), testMethodName));
            } else {
                log.debug("Running test class {}", className);
                junit.run(getTestClass(className));
            }
        }
    } finally {
        if (createContext) {
            SlingTestContextProvider.deleteContext();
        }
    }
}
Also used : JUnitCore(org.junit.runner.JUnitCore)

Example 84 with JUnitCore

use of org.junit.runner.JUnitCore in project bayou by capergroup.

the class FloodGage method run.

/**
 * Parses "trials.xml" as found as a resource on the current class path and executes the trials against
 * the given Synthesizer reporting progress to the given View.
 *
 * Expects a trialpack to be on the current classpath.
 *
 * @param synthesizer the Synthesizer to use for creating programs from draft programs identified in trials.
 * @param view the UI component for reporting execution progress.
 * @throws IOException if there is a program reading resources (like "trails.xml") on the classpath.
 * @throws ParseException if "trials.xml" is not of the expected format
 * @throws ClassCastException if "PassProgram" or "PassProgramTest" cannot be loaded from teh current classpath.
 */
void run(Synthesizer synthesizer, View view) throws IOException, ParseException, ClassNotFoundException {
    if (synthesizer == null)
        throw new NullPointerException("synthesizer");
    if (view == null)
        throw new NullPointerException("view");
    /*
         * Parse trials.xml from inside the trialpack (assumed to be on classpath) into a Directive structure.
         */
    Directive directive;
    {
        // We expect the trialpack jar file to be on the classpath.  That jar file should have a
        // trails.xml file its root directory.  So look for it at just "trails.xml" path.
        String trailsXml = new String(getResource("trials.xml"), StandardCharsets.UTF_8);
        directive = DirectiveXmlV1Parser.makeDefault().parse(trailsXml);
    }
    /*
         * Test the test suite by asserting that all test cases pass when given the pass program.
         *
         * Stop the program if this is not the case.
         */
    // expect PassProgram class inside the trailpack which is assumed to be on the class path
    Class passProgram = getClass().getClassLoader().loadClass("PassProgram");
    // expect PassProgramTest class inside the trailpack which is assumed to be on the class path
    Class passProgramTestSuite = getClass().getClassLoader().loadClass("PassProgramTest");
    view.declareTestingTestSuite(passProgramTestSuite, passProgram);
    // run the test cases against PassProgram
    Result result = new JUnitCore().run(passProgramTestSuite);
    view.declareNumberOfTestCasesInSuite(result.getRunCount());
    if (// if the pass program did not pass the test suite
    result.getFailureCount() > 0) {
        for (Failure f : result.getFailures()) view.declarePassProgramTestFailure(f.getTrace());
    } else // pass program did pass the test suite, proceed to running the user specified trials
    {
        List<Trial> trials = makeTrials(directive, DraftBuilderBayou1_1_0::new);
        TrialsRunner.runTrails(trials, synthesizer, view);
    }
}
Also used : Trial(edu.rice.cs.caper.floodgage.application.floodgage.model.plan.Trial) JUnitCore(org.junit.runner.JUnitCore) DraftBuilderBayou1_1_0(edu.rice.cs.caper.floodgage.application.floodgage.draft_building.DraftBuilderBayou1_1_0) Directive(edu.rice.cs.caper.floodgage.application.floodgage.model.directive.Directive) Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result)

Example 85 with JUnitCore

use of org.junit.runner.JUnitCore in project vcell by virtualcell.

the class MathVisitor method main.

public static void main(String[] args) {
    Request req = Request.method(MathVisitor.class, "batchScan");
    JUnitCore core = new JUnitCore();
    Result res = core.run(req);
    for (Failure f : res.getFailures()) {
        System.err.println("Failure:  " + f.toString());
    }
    System.exit(0);
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request) Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result)

Aggregations

JUnitCore (org.junit.runner.JUnitCore)173 Result (org.junit.runner.Result)104 Test (org.junit.Test)88 Request (org.junit.runner.Request)33 Failure (org.junit.runner.notification.Failure)24 PrintableResult.testResult (org.junit.experimental.results.PrintableResult.testResult)22 RunListener (org.junit.runner.notification.RunListener)17 Description (org.junit.runner.Description)16 ArrayList (java.util.ArrayList)14 TestResult (junit.framework.TestResult)14 TextListener (org.junit.internal.TextListener)12 Runner (org.junit.runner.Runner)9 RandomizedRunner (com.carrotsearch.randomizedtesting.RandomizedRunner)7 TestSuiteModel (com.google.testing.junit.runner.model.TestSuiteModel)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 OutputStream (java.io.OutputStream)5 CategoryFilter (org.junit.experimental.categories.Categories.CategoryFilter)5 File (java.io.File)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 InOrder (org.mockito.InOrder)4