Search in sources :

Example 26 with Request

use of org.junit.runner.Request in project zm-mailbox by Zimbra.

the class ZimbraSuite method runTestsInternal.

private static TestResults runTestsInternal(Collection<Class> testClasses, Iterable<Request> requests) {
    JUnitCore junit = new JUnitCore();
    junit.addListener(new TestLogger());
    TestResults results = new TestResults();
    junit.addListener(results);
    if (testClasses != null && testClasses.size() > 0) {
        Class<?>[] classArray = new Class<?>[testClasses.size()];
        testClasses.toArray(classArray);
        junit.run(classArray);
    }
    if (requests != null) {
        for (Request request : requests) {
            junit.run(request);
        }
    }
    return results;
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request)

Example 27 with Request

use of org.junit.runner.Request in project geode by apache.

the class CategoryWithParameterizedRunnerFactoryTest method testWorkingCategoryAndParameterized.

@Test
public void testWorkingCategoryAndParameterized() {
    Request request = Request.aClass(WorkingCategoryClass.class);
    ExposedParameterized runner = (ExposedParameterized) request.getRunner();
    request = request.filterWith(new CategoryFilter((ExposedGetAnnotations) runner.getChildren().get(0)));
    Result result = new JUnitCore().run(request);
    assertEquals(2, result.getRunCount());
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request) Result(org.junit.runner.Result) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 28 with Request

use of org.junit.runner.Request in project jmeter by apache.

the class AllTests method main.

/**
     * Starts a run through all unit tests found in the specified classpaths.
     * The first argument should be a list of paths to search. The second
     * argument is optional and specifies a properties file used to initialize
     * logging. The third argument is also optional, and specifies a class that
     * implements the UnitTestManager interface. This provides a means of
     * initializing your application with a configuration file prior to the
     * start of any unit tests.
     * 
     * @param args
     *            the command line arguments
     */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("You must specify a comma-delimited list of paths to search " + "for unit tests");
        return;
    }
    String home = new File(System.getProperty("user.dir")).getParent();
    System.out.println("Setting JMeterHome: " + home);
    JMeterUtils.setJMeterHome(home);
    initializeManager(args);
    log.info("JMeterVersion={}", JMeterUtils.getJMeterVersion());
    System.out.println("JMeterVersion=" + JMeterUtils.getJMeterVersion());
    logprop("java.version", true);
    logprop("java.vm.name");
    logprop("java.vendor");
    logprop("java.home", true);
    logprop("file.encoding", true);
    // Display actual encoding used (will differ if file.encoding is not recognised)
    System.out.println("default encoding=" + Charset.defaultCharset());
    log.info("default encoding={}", Charset.defaultCharset());
    logprop("user.home");
    logprop("user.dir", true);
    logprop("user.language");
    logprop("user.region");
    logprop("user.country");
    logprop("user.variant");
    log.info("Locale={}", Locale.getDefault());
    System.out.println("Locale=" + Locale.getDefault());
    logprop("os.name", true);
    logprop("os.version", true);
    logprop("os.arch");
    logprop("java.class.version");
    String cp = System.getProperty("java.class.path");
    String[] cpe = JOrphanUtils.split(cp, java.io.File.pathSeparator);
    StringBuilder sb = new StringBuilder(3000);
    sb.append("java.class.path=");
    for (String path : cpe) {
        sb.append("\n");
        sb.append(path);
        if (new File(path).exists()) {
            sb.append(" - OK");
        } else {
            sb.append(" - ??");
        }
    }
    log.info(sb.toString());
    try {
        int maxKeyLen = Cipher.getMaxAllowedKeyLength("AES");
        System.out.println("JCE max key length = " + maxKeyLen);
    } catch (NoSuchAlgorithmException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    System.out.println("+++++++++++");
    logprop("java.awt.headless", true);
    logprop("java.awt.graphicsenv", true);
    System.out.println("------------");
    try {
        System.out.println("Searching junit tests in : " + args[0]);
        List<String> tests = findJMeterJUnitTests(args[0]);
        Class<?>[] classes = asClasses(tests);
        JUnitCore jUnitCore = new JUnitCore();
        // this listener is in the internal junit package
        // if it breaks, replace it with a custom text listener
        RunListener listener = new TextListener(new RealSystem());
        jUnitCore.addListener(listener);
        Request request = Request.classes(new Computer(), classes);
        if (GraphicsEnvironment.isHeadless()) {
            request = request.filterWith(new ExcludeCategoryFilter(NeedGuiTests.class));
        }
        Result result = jUnitCore.run(request);
        System.exit(result.wasSuccessful() ? 0 : 1);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request) TextListener(org.junit.internal.TextListener) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ExcludeCategoryFilter(org.apache.jmeter.junit.categories.ExcludeCategoryFilter) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) RunListener(org.junit.runner.notification.RunListener) Result(org.junit.runner.Result) RealSystem(org.junit.internal.RealSystem) Computer(org.junit.runner.Computer) File(java.io.File)

Example 29 with Request

use of org.junit.runner.Request 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 30 with Request

use of org.junit.runner.Request in project bazel by bazelbuild.

the class JUnit4TestXmlListenerTest method assumptionViolationsAreReportedAsSkippedTests.

@Test
public void assumptionViolationsAreReportedAsSkippedTests() throws Exception {
    TestSuiteModelSupplier mockModelSupplier = mock(TestSuiteModelSupplier.class);
    TestSuiteModel mockModel = mock(TestSuiteModel.class);
    CancellableRequestFactory mockRequestFactory = mock(CancellableRequestFactory.class);
    OutputStream mockXmlStream = mock(OutputStream.class);
    JUnit4TestXmlListener listener = new JUnit4TestXmlListener(mockModelSupplier, mockRequestFactory, fakeSignalHandlers, mockXmlStream, errPrintStream);
    Request request = Request.classWithoutSuiteMethod(TestWithAssumptionViolation.class);
    Description suiteDescription = request.getRunner().getDescription();
    Description testDescription = suiteDescription.getChildren().get(0);
    when(mockModelSupplier.get()).thenReturn(mockModel);
    JUnitCore core = new JUnitCore();
    core.addListener(listener);
    core.run(request);
    assertEquals("no output to stderr expected", 0, errStream.size());
    InOrder inOrder = inOrder(mockModel);
    inOrder.verify(mockModel).testSkipped(testDescription);
    inOrder.verify(mockModel).writeAsXml(mockXmlStream);
    verify(mockRequestFactory, never()).cancelRun();
}
Also used : Description(org.junit.runner.Description) InOrder(org.mockito.InOrder) JUnitCore(org.junit.runner.JUnitCore) TestSuiteModel(com.google.testing.junit.runner.model.TestSuiteModel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Request(org.junit.runner.Request) Test(org.junit.Test)

Aggregations

Request (org.junit.runner.Request)54 Test (org.junit.Test)37 JUnitCore (org.junit.runner.JUnitCore)32 Result (org.junit.runner.Result)22 Description (org.junit.runner.Description)20 TestSuiteModel (com.google.testing.junit.runner.model.TestSuiteModel)8 Runner (org.junit.runner.Runner)8 PrintableResult.testResult (org.junit.experimental.results.PrintableResult.testResult)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 RunListener (org.junit.runner.notification.RunListener)6 OutputStream (java.io.OutputStream)5 CategoryFilter (org.junit.experimental.categories.Categories.CategoryFilter)5 Filter (org.junit.runner.manipulation.Filter)5 Failure (org.junit.runner.notification.Failure)5 IOException (java.io.IOException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 InOrder (org.mockito.InOrder)4 ArrayList (java.util.ArrayList)3 Computer (org.junit.runner.Computer)3 TestNode (com.google.testing.junit.runner.model.TestNode)2