Search in sources :

Example 6 with TextListener

use of org.junit.internal.TextListener 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 7 with TextListener

use of org.junit.internal.TextListener in project hbase by apache.

the class IntegrationTestsDriver method doWork.

@Override
protected int doWork() throws Exception {
    //this is called from the command line, so we should set to use the distributed cluster
    IntegrationTestingUtility.setUseDistributedCluster(conf);
    Class<?>[] classes = findIntegrationTestClasses();
    LOG.info("Found " + classes.length + " integration tests to run:");
    for (Class<?> aClass : classes) {
        LOG.info("  " + aClass);
    }
    JUnitCore junit = new JUnitCore();
    junit.addListener(new TextListener(System.out));
    Result result = junit.run(classes);
    return result.wasSuccessful() ? 0 : 1;
}
Also used : JUnitCore(org.junit.runner.JUnitCore) TextListener(org.junit.internal.TextListener) Result(org.junit.runner.Result)

Example 8 with TextListener

use of org.junit.internal.TextListener in project bazel by bazelbuild.

the class JUnit4RunnerTest method getExpectedOutput.

private ByteArrayOutputStream getExpectedOutput(Class<?> testClass) {
    JUnitCore core = new JUnitCore();
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    PrintStream printStream = new PrintStream(byteStream);
    printStream.println("JUnit4 Test Runner");
    RunListener listener = new TextListener(printStream);
    core.addListener(listener);
    Request request = Request.classWithoutSuiteMethod(testClass);
    core.run(request);
    printStream.close();
    return byteStream;
}
Also used : PrintStream(java.io.PrintStream) JUnitCore(org.junit.runner.JUnitCore) Request(org.junit.runner.Request) TextListener(org.junit.internal.TextListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RunListener(org.junit.runner.notification.RunListener)

Example 9 with TextListener

use of org.junit.internal.TextListener in project h2o-3 by h2oai.

the class H2OTestRunner method run.

public Result run(String[] args) throws Exception {
    // List all classes - adapted from JUnitCore code
    List<Class<?>> classes = new ArrayList<Class<?>>();
    List<Failure> missingClasses = new ArrayList<Failure>();
    for (String arg : args) {
        try {
            classes.add(Class.forName(arg));
        } catch (ClassNotFoundException e) {
            Description description = Description.createSuiteDescription(arg);
            Failure failure = new Failure(description, e);
            missingClasses.add(failure);
        }
    }
    // Create standard JUnitCore
    JUnitCore jcore = new JUnitCore();
    // Create default "system"
    JUnitSystem jsystem = new RealSystem();
    // Setup default listener
    jcore.addListener(new TextListener(jsystem));
    // Add XML generator listener
    jcore.addListener(new XMLTestReporter());
    Result result = jcore.run(classes.toArray(new Class[0]));
    for (Failure each : missingClasses) {
        System.err.println("FAIL Missing class in H2OTestRunner: " + each);
        result.getFailures().add(each);
    }
    return result;
}
Also used : Description(org.junit.runner.Description) JUnitCore(org.junit.runner.JUnitCore) ArrayList(java.util.ArrayList) JUnitSystem(org.junit.internal.JUnitSystem) TextListener(org.junit.internal.TextListener) Result(org.junit.runner.Result) RealSystem(org.junit.internal.RealSystem) Failure(org.junit.runner.notification.Failure)

Example 10 with TextListener

use of org.junit.internal.TextListener in project junit4 by junit-team.

the class PrintableResult method toString.

@Override
public String toString() {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    new TextListener(new PrintStream(stream)).testRunFinished(result);
    return stream.toString();
}
Also used : PrintStream(java.io.PrintStream) TextListener(org.junit.internal.TextListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

TextListener (org.junit.internal.TextListener)15 JUnitCore (org.junit.runner.JUnitCore)12 Result (org.junit.runner.Result)6 RunListener (org.junit.runner.notification.RunListener)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 PrintStream (java.io.PrintStream)2 JUnitSystem (org.junit.internal.JUnitSystem)2 RealSystem (org.junit.internal.RealSystem)2 Description (org.junit.runner.Description)2 Request (org.junit.runner.Request)2 Failure (org.junit.runner.notification.Failure)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 Pattern (java.util.regex.Pattern)1