Search in sources :

Example 91 with Failure

use of org.junit.runner.notification.Failure in project sling by apache.

the class TeleporterHttpClient method runTests.

void runTests(String testSelectionPath, int testReadyTimeoutSeconds) throws MalformedURLException, IOException, MultipleFailureException {
    final String testUrl = baseUrl + "/" + testServletPath + testSelectionPath + ".junit_result";
    // Wait for non-404 response that signals that test bundle is ready
    final long timeout = System.currentTimeMillis() + (testReadyTimeoutSeconds * 1000L);
    final ExponentialBackoffDelay delay = new ExponentialBackoffDelay(25, 1000);
    while (true) {
        if (getHttpGetStatus(testUrl).getStatus() == 200) {
            break;
        }
        if (System.currentTimeMillis() > timeout) {
            fail("Timeout waiting for test at " + testUrl + " (" + testReadyTimeoutSeconds + " seconds)");
            break;
        }
        delay.waitNextDelay();
    }
    final HttpURLConnection c = (HttpURLConnection) new URL(testUrl).openConnection();
    try {
        setConnectionCredentials(c);
        c.setRequestMethod("POST");
        c.setUseCaches(false);
        c.setDoOutput(true);
        c.setDoInput(true);
        c.setInstanceFollowRedirects(false);
        final int status = c.getResponseCode();
        if (status != 200) {
            throw new IOException("Got status code " + status + " for " + testUrl);
        }
        final Result result = (Result) new ObjectInputStream(c.getInputStream()).readObject();
        if (result.getFailureCount() > 0) {
            final List<Throwable> failures = new ArrayList<Throwable>(result.getFailureCount());
            for (Failure f : result.getFailures()) {
                failures.add(f.getException());
            }
            throw new MultipleFailureException(failures);
        }
    } catch (ClassNotFoundException e) {
        throw new IOException("Exception reading test results:" + e, e);
    } finally {
        cleanup(c);
    }
}
Also used : ArrayList(java.util.ArrayList) JsonString(javax.json.JsonString) IOException(java.io.IOException) URL(java.net.URL) Result(org.junit.runner.Result) HttpURLConnection(java.net.HttpURLConnection) MultipleFailureException(org.junit.runners.model.MultipleFailureException) Failure(org.junit.runner.notification.Failure) ObjectInputStream(java.io.ObjectInputStream)

Example 92 with Failure

use of org.junit.runner.notification.Failure in project sling by apache.

the class PerformanceRunnerTest method assertTestFails.

private void assertTestFails(Class<?> testClass, String message) {
    Result result = runTest(testClass);
    boolean isInitializationError = false;
    for (Failure failure : result.getFailures()) {
        isInitializationError = isInitializationError || failure.getException().getMessage().equals(message);
    }
    Assert.assertEquals(true, isInitializationError);
}
Also used : Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result)

Example 93 with Failure

use of org.junit.runner.notification.Failure 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 94 with Failure

use of org.junit.runner.notification.Failure in project codeu_project_2017 by PabloG6.

the class TestRunner method main.

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());
}
Also used : Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result)

Example 95 with Failure

use of org.junit.runner.notification.Failure 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

Failure (org.junit.runner.notification.Failure)194 Test (org.junit.Test)101 Result (org.junit.runner.Result)91 Description (org.junit.runner.Description)40 IOException (java.io.IOException)32 UnitTest (org.apache.geode.test.junit.categories.UnitTest)27 JUnitCore (org.junit.runner.JUnitCore)24 FileInputStream (java.io.FileInputStream)20 InputStream (java.io.InputStream)20 RunListener (org.junit.runner.notification.RunListener)19 ArrayList (java.util.ArrayList)11 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ComparisonFailure (org.junit.ComparisonFailure)9 JUnit4TestListener (com.intellij.junit4.JUnit4TestListener)7 RunNotifier (org.junit.runner.notification.RunNotifier)7 ResourceImpl (ddf.catalog.resource.impl.ResourceImpl)6 Request (org.junit.runner.Request)6 BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)5 Before (org.junit.Before)5 Runner (org.junit.runner.Runner)5