mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
test discovery: allow to listen to TestingStarted/Finished
This commit is contained in:
@@ -48,4 +48,8 @@ public class TestDiscoveryListener {
|
||||
return null; //should not happen
|
||||
}
|
||||
}
|
||||
|
||||
public void testRunStarted(String name) {}
|
||||
|
||||
public void testRunFinished(String name) {}
|
||||
}
|
||||
|
||||
@@ -39,18 +39,12 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
|
||||
final Request request = JUnit4TestRunnerUtil.buildRequest(args, name, sendTree);
|
||||
if (request == null) return -1;
|
||||
final Runner testRunner = request.getRunner();
|
||||
Description description = null;
|
||||
try {
|
||||
Description description = testRunner.getDescription();
|
||||
description = getDescription(request, testRunner);
|
||||
if (description == null) {
|
||||
System.err.println("Nothing found to run. Runner " + testRunner.getClass().getName() + " provides no description.");
|
||||
return -1;
|
||||
}
|
||||
if (request instanceof ClassRequest) {
|
||||
description = getSuiteMethodDescription(request, description);
|
||||
}
|
||||
else if (request instanceof FilterRequest) {
|
||||
description = getFilteredDescription(request, description);
|
||||
}
|
||||
|
||||
if (myTestsListener instanceof JUnit4TestListener) {
|
||||
if (sendTree) {
|
||||
@@ -68,6 +62,7 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
|
||||
}
|
||||
|
||||
try {
|
||||
final Description runnerDescription = description;
|
||||
final JUnitCore runner = new JUnitCore();
|
||||
runner.addListener(myTestsListener);
|
||||
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
@@ -80,6 +75,18 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
|
||||
public void testFinished(Description description) throws Exception {
|
||||
junitListener.testFinished(JUnit4ReflectionUtil.getClassName(description), JUnit4ReflectionUtil.getMethodName(description));
|
||||
}
|
||||
|
||||
public void testRunStarted(Description description) throws Exception {
|
||||
if (junitListener instanceof IDEAJUnitListenerEx) {
|
||||
((IDEAJUnitListenerEx)junitListener).testRunStarted(description.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
public void testRunFinished(Result result) throws Exception {
|
||||
if (junitListener instanceof IDEAJUnitListenerEx) {
|
||||
((IDEAJUnitListenerEx)junitListener).testRunFinished(runnerDescription.getDisplayName());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
long startTime = System.currentTimeMillis();
|
||||
@@ -130,6 +137,21 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
|
||||
}
|
||||
}
|
||||
|
||||
private static Description getDescription(Request request, Runner testRunner) throws NoSuchFieldException, IllegalAccessException {
|
||||
Description description = testRunner.getDescription();
|
||||
if (description == null) {
|
||||
System.err.println("Nothing found to run. Runner " + testRunner.getClass().getName() + " provides no description.");
|
||||
return null;
|
||||
}
|
||||
if (request instanceof ClassRequest) {
|
||||
description = getSuiteMethodDescription(request, description);
|
||||
}
|
||||
else if (request instanceof FilterRequest) {
|
||||
description = getFilteredDescription(request, description);
|
||||
}
|
||||
return description;
|
||||
}
|
||||
|
||||
private static Description getFilteredDescription(Request request, Description description) throws NoSuchFieldException, IllegalAccessException {
|
||||
Field field;
|
||||
try {
|
||||
@@ -200,22 +222,15 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
|
||||
final Request request = JUnit4TestRunnerUtil.buildRequest(args, name, false);
|
||||
if (request == null) return null;
|
||||
final Runner testRunner = request.getRunner();
|
||||
Description description = null;
|
||||
try {
|
||||
description = testRunner.getDescription();
|
||||
if (request instanceof ClassRequest) {
|
||||
description = getSuiteMethodDescription(request, description);
|
||||
}
|
||||
else if (request instanceof FilterRequest) {
|
||||
description = getFilteredDescription(request, description);
|
||||
}
|
||||
return getDescription(request, testRunner);
|
||||
}
|
||||
catch (Exception e) {
|
||||
//noinspection HardCodedStringLiteral
|
||||
System.err.println("Internal Error occured.");
|
||||
e.printStackTrace(System.err);
|
||||
return null;
|
||||
}
|
||||
return description;
|
||||
}
|
||||
|
||||
public List getChildTests(Object description) {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.intellij.junit4;
|
||||
|
||||
import com.intellij.execution.TestDiscoveryListener;
|
||||
import com.intellij.rt.execution.junit.IDEAJUnitListener;
|
||||
import com.intellij.rt.execution.junit.IDEAJUnitListenerEx;
|
||||
|
||||
public class JUnitTestDiscoveryListener extends TestDiscoveryListener implements IDEAJUnitListener {
|
||||
}
|
||||
public class JUnitTestDiscoveryListener extends TestDiscoveryListener implements IDEAJUnitListenerEx {}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.rt.execution.junit;
|
||||
|
||||
public interface IDEAJUnitListenerEx extends IDEAJUnitListener {
|
||||
void testRunStarted(String name);
|
||||
void testRunFinished(String name);
|
||||
}
|
||||
@@ -17,7 +17,7 @@ package org.testng;
|
||||
|
||||
import com.intellij.execution.TestDiscoveryListener;
|
||||
|
||||
public class TestNGTestDiscoveryListener extends TestDiscoveryListener implements IDEATestNGListener {
|
||||
public class TestNGTestDiscoveryListener extends TestDiscoveryListener implements IDEATestNGListener, ISuiteListener {
|
||||
public void onTestStart(ITestResult result) {
|
||||
testStarted(result.getTestClass().getName(), result.getTestName());
|
||||
}
|
||||
@@ -45,4 +45,12 @@ public class TestNGTestDiscoveryListener extends TestDiscoveryListener implement
|
||||
private void onTestEnded(ITestResult result) {
|
||||
testFinished(result.getTestClass().getName(), result.getName());
|
||||
}
|
||||
|
||||
public void onStart(ISuite suite) {
|
||||
testRunStarted(suite.getName());
|
||||
}
|
||||
|
||||
public void onFinish(ISuite suite) {
|
||||
testRunFinished(suite.getName());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user