Search in sources :

Example 71 with JUnitCore

use of org.junit.runner.JUnitCore 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 72 with JUnitCore

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

the class DBTest method execCmd.

@Override
protected void execCmd(List<String> args) {
    if (isVerbose()) {
        for (String k : params) System.out.printf("%-20s = %-20s\n", k, params.get(k));
        System.out.println();
    }
    Connection jdbc = getModStore().getConnection().getSqlConnection();
    // Hack to pass to calculated parameters to the test subsystem.
    sdb.test.Env.set(jdbc, params, false);
    JUnitCore x = new org.junit.runner.JUnitCore();
    //RunListener listener = new TextListener2() ;
    RunListener listener = new TextListener2(System.out);
    x.addListener(listener);
    //x.run(sdb.test.AllTests.class) ;
    System.out.println("String basic");
    x.run(TestStringBasic.class);
    System.out.println("String I18N");
    x.run(TestI18N.class);
// Better way of having parameters for a class than a @Parameterised test of one thing?
//        Request request = Request.aClass(sdb.test.T.class) ;
//        x.run(request) ;
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Connection(java.sql.Connection) TextListener2(sdb.junit.TextListener2) RunListener(org.junit.runner.notification.RunListener)

Example 73 with JUnitCore

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

the class RunAllTests method main.

public static void main(String[] args) {
    List<Class<?>> classes = new ArrayList<>();
    for (Class<?> cls : VM.listClasses(Object.class, ClassLoader.getSystemClassLoader())) {
        if (!cls.getName().startsWith("junit.") && !cls.getName().startsWith("org.junit.")) {
            if (TestCase.class.isAssignableFrom(cls)) {
                classes.add(cls);
                continue;
            }
            for (Method m : cls.getMethods()) {
                if (m.getAnnotation(Test.class) != null) {
                    classes.add(cls);
                    break;
                }
            }
        }
    }
    JUnitCore jc = new JUnitCore();
    jc.addListener(new TextListener(System.out));
    jc.run(classes.toArray(new Class[classes.size()]));
    System.out.flush();
    System.exit(0);
}
Also used : JUnitCore(org.junit.runner.JUnitCore) Test(org.junit.Test) ArrayList(java.util.ArrayList) TextListener(org.junit.internal.TextListener) Method(java.lang.reflect.Method)

Example 74 with JUnitCore

use of org.junit.runner.JUnitCore in project spring-boot by spring-projects.

the class DelegateTestRunner method run.

public static void run(Class<?>[] testClasses, Result result) {
    JUnitCore jUnitCore = new JUnitCore();
    jUnitCore.addListener(new TextListener(System.out));
    jUnitCore.addListener(result.createListener());
    jUnitCore.run(testClasses);
}
Also used : JUnitCore(org.junit.runner.JUnitCore) TextListener(org.junit.internal.TextListener)

Example 75 with JUnitCore

use of org.junit.runner.JUnitCore in project spring-boot by spring-projects.

the class Mockito110Tests method runTests.

private void runTests(Class<?> testClass) {
    Result result = new JUnitCore().run(testClass);
    for (Failure failure : result.getFailures()) {
        System.err.println(failure.getTrace());
    }
    assertThat(result.getFailureCount()).isEqualTo(0);
    assertThat(result.getRunCount()).isGreaterThan(0);
}
Also used : JUnitCore(org.junit.runner.JUnitCore) 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