Search in sources :

Example 1 with IDEAJUnitListener

use of com.intellij.rt.execution.junit.IDEAJUnitListener in project intellij-community by JetBrains.

the class JUnit4IdeaTestRunner method startRunnerWithArgs.

public int startRunnerWithArgs(String[] args, String name, int count, boolean sendTree) {
    try {
        final Request request = JUnit4TestRunnerUtil.buildRequest(args, name, sendTree);
        if (request == null)
            return -2;
        final Runner testRunner = request.getRunner();
        Description description = getDescription(request, testRunner);
        if (description == null) {
            return -2;
        }
        if (sendTree) {
            do {
                ((JUnit4TestListener) myTestsListener).sendTree(description);
            } while (--count > 0);
        }
        final JUnitCore runner = new JUnitCore();
        runner.addListener(myTestsListener);
        for (Iterator iterator = myListeners.iterator(); iterator.hasNext(); ) {
            final IDEAJUnitListener junitListener = (IDEAJUnitListener) Class.forName((String) iterator.next()).newInstance();
            runner.addListener(new MyCustomRunListenerWrapper(junitListener, description.getDisplayName()));
        }
        final Result result = runner.run(testRunner);
        return result.wasSuccessful() ? 0 : -1;
    } catch (Exception e) {
        e.printStackTrace(System.err);
        return -2;
    }
}
Also used : IdeaTestRunner(com.intellij.rt.execution.junit.IdeaTestRunner) IDEAJUnitListener(com.intellij.rt.execution.junit.IDEAJUnitListener) FilterRequest(org.junit.internal.requests.FilterRequest) ClassRequest(org.junit.internal.requests.ClassRequest) Iterator(java.util.Iterator)

Example 2 with IDEAJUnitListener

use of com.intellij.rt.execution.junit.IDEAJUnitListener in project intellij-community by JetBrains.

the class JUnit5IdeaTestRunner method startRunnerWithArgs.

@Override
public int startRunnerWithArgs(String[] args, String name, int count, boolean sendTree) {
    try {
        myListener.initialize();
        final String[] packageNameRef = new String[1];
        final LauncherDiscoveryRequest discoveryRequest = JUnit5TestRunnerUtil.buildRequest(args, packageNameRef);
        myTestPlan = myLauncher.discover(discoveryRequest);
        for (Object listenerClassName : myListeners) {
            final IDEAJUnitListener junitListener = (IDEAJUnitListener) Class.forName((String) listenerClassName).newInstance();
            myLauncher.registerTestExecutionListeners(new MyCustomListenerWrapper(junitListener));
        }
        if (sendTree) {
            do {
                myListener.sendTree(myTestPlan, packageNameRef[0]);
            } while (--count > 0);
        }
        myLauncher.execute(discoveryRequest);
        return myListener.wasSuccessful() ? 0 : -1;
    } catch (Exception e) {
        System.err.println("Internal Error occurred.");
        e.printStackTrace(System.err);
        return -2;
    }
}
Also used : IDEAJUnitListener(com.intellij.rt.execution.junit.IDEAJUnitListener)

Aggregations

IDEAJUnitListener (com.intellij.rt.execution.junit.IDEAJUnitListener)2 IdeaTestRunner (com.intellij.rt.execution.junit.IdeaTestRunner)1 Iterator (java.util.Iterator)1 ClassRequest (org.junit.internal.requests.ClassRequest)1 FilterRequest (org.junit.internal.requests.FilterRequest)1