mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
try sm runner for testng
This commit is contained in:
@@ -292,3 +292,4 @@ comment.by.line.bulk.lines.trigger=100
|
||||
scene.builder.start.executable=true
|
||||
search.everywhere.enabled=false
|
||||
junit_sm_runner=false
|
||||
testng_sm_runner=false
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.intellij.openapi.project.DumbModeAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.psi.*;
|
||||
@@ -108,7 +109,7 @@ public class SearchingForTestsTask extends Task.Backgroundable {
|
||||
writeTempFile();
|
||||
finish();
|
||||
|
||||
myClient.startListening(myConfig);
|
||||
if (!Registry.is("testng_sm_runner", false)) myClient.startListening(myConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,12 +26,18 @@ import com.intellij.ExtensionPoints;
|
||||
import com.intellij.debugger.engine.DebuggerUtils;
|
||||
import com.intellij.execution.*;
|
||||
import com.intellij.execution.configurations.*;
|
||||
import com.intellij.execution.junit.RuntimeConfigurationProducer;
|
||||
import com.intellij.execution.process.OSProcessHandler;
|
||||
import com.intellij.execution.process.ProcessAdapter;
|
||||
import com.intellij.execution.process.ProcessEvent;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.runners.ProgramRunner;
|
||||
import com.intellij.execution.testframework.*;
|
||||
import com.intellij.execution.testframework.sm.SMTestRunnerConnectionUtil;
|
||||
import com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties;
|
||||
import com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView;
|
||||
import com.intellij.execution.testframework.ui.BaseTestsOutputConsoleView;
|
||||
import com.intellij.execution.ui.ConsoleView;
|
||||
import com.intellij.execution.ui.ConsoleViewContentType;
|
||||
import com.intellij.execution.util.JavaParametersUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -66,6 +72,7 @@ import com.theoryinpractice.testng.model.*;
|
||||
import com.theoryinpractice.testng.ui.TestNGConsoleView;
|
||||
import com.theoryinpractice.testng.ui.TestNGResults;
|
||||
import com.theoryinpractice.testng.ui.actions.RerunFailedTestsAction;
|
||||
import jetbrains.buildServer.messages.serviceMessages.ServiceMessageTypes;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.testng.CommandLineArgs;
|
||||
@@ -86,6 +93,7 @@ import java.net.UnknownHostException;
|
||||
|
||||
public class TestNGRunnableState extends JavaCommandLineState {
|
||||
private static final Logger LOG = Logger.getInstance("TestNG Runner");
|
||||
private static final String TESTNG_TEST_FRAMEWORK_NAME = "TestNG";
|
||||
private final ConfigurationPerRunnerSettings myConfigurationPerRunnerSettings;
|
||||
private final TestNGConfiguration config;
|
||||
private final RunnerSettings runnerSettings;
|
||||
@@ -123,6 +131,10 @@ public class TestNGRunnableState extends JavaCommandLineState {
|
||||
|
||||
@Override
|
||||
public ExecutionResult execute(@NotNull final Executor executor, @NotNull final ProgramRunner runner) throws ExecutionException {
|
||||
final boolean smRunner = Registry.is("testng_sm_runner", false);
|
||||
if (smRunner) {
|
||||
return startSMRunner(executor);
|
||||
}
|
||||
OSProcessHandler processHandler = startProcess();
|
||||
final TreeRootNode unboundOutputRoot = new TreeRootNode();
|
||||
final TestNGConsoleView console = new TestNGConsoleView(config, runnerSettings, myConfigurationPerRunnerSettings, unboundOutputRoot,
|
||||
@@ -229,6 +241,62 @@ public class TestNGRunnableState extends JavaCommandLineState {
|
||||
return result;
|
||||
}
|
||||
|
||||
private ExecutionResult startSMRunner(Executor executor) throws ExecutionException {
|
||||
getJavaParameters().getVMParametersList().add("-Didea.testng.sm_runner");
|
||||
getJavaParameters().getClassPath().add(PathUtil.getJarPathForClass(ServiceMessageTypes.class));
|
||||
|
||||
OSProcessHandler handler = startProcess();
|
||||
TestConsoleProperties testConsoleProperties = new SMTRunnerConsoleProperties(
|
||||
new RuntimeConfigurationProducer.DelegatingRuntimeConfiguration<TestNGConfiguration>(
|
||||
(TestNGConfiguration)getEnvironment().getRunProfile()),
|
||||
TESTNG_TEST_FRAMEWORK_NAME,
|
||||
executor
|
||||
);
|
||||
|
||||
testConsoleProperties.setIfUndefined(TestConsoleProperties.HIDE_PASSED_TESTS, false);
|
||||
|
||||
final BaseTestsOutputConsoleView smtConsoleView = SMTestRunnerConnectionUtil.createConsoleWithCustomLocator(
|
||||
TESTNG_TEST_FRAMEWORK_NAME,
|
||||
testConsoleProperties,
|
||||
getEnvironment().getRunnerSettings(),
|
||||
getEnvironment().getConfigurationSettings(), null);
|
||||
|
||||
|
||||
Disposer.register(getEnvironment().getProject(), smtConsoleView);
|
||||
smtConsoleView.attachToProcess(handler);
|
||||
final RerunFailedTestsAction rerunFailedTestsAction = new RerunFailedTestsAction(smtConsoleView);
|
||||
rerunFailedTestsAction.init(testConsoleProperties, getEnvironment());
|
||||
rerunFailedTestsAction.setModelProvider(new Getter<TestFrameworkRunningModel>() {
|
||||
@Override
|
||||
public TestFrameworkRunningModel get() {
|
||||
return ((SMTRunnerConsoleView)smtConsoleView).getResultsViewer();
|
||||
}
|
||||
});
|
||||
|
||||
final DefaultExecutionResult result = new DefaultExecutionResult(smtConsoleView, handler);
|
||||
result.setRestartActions(rerunFailedTestsAction);
|
||||
|
||||
JavaRunConfigurationExtensionManager.getInstance().attachExtensionsToProcess(config, handler, runnerSettings);
|
||||
final SearchingForTestsTask task = createSearchingForTestsTask(myServerSocket, config, myTempFile);
|
||||
handler.addProcessListener(new ProcessAdapter() {
|
||||
@Override
|
||||
public void processTerminated(final ProcessEvent event) {
|
||||
|
||||
if (mySearchForTestIndicator != null && !mySearchForTestIndicator.isCanceled()) {
|
||||
task.finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startNotified(final ProcessEvent event) {
|
||||
mySearchForTestIndicator = new BackgroundableProcessIndicator(task);
|
||||
ProgressManagerImpl.runProcessWithProgressAsynchronously(task, mySearchForTestIndicator);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JavaParameters createJavaParameters() throws ExecutionException {
|
||||
final Project project = config.getProject();
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
<orderEntry type="library" name="TestNG" level="project" />
|
||||
<orderEntry type="module" module-name="java-indexing-api" />
|
||||
<orderEntry type="module" module-name="xml" scope="TEST" />
|
||||
<orderEntry type="module" module-name="smRunner" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
66
plugins/testng_rt/src/org/testng/IDEARemoteTestNG.java
Normal file
66
plugins/testng_rt/src/org/testng/IDEARemoteTestNG.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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 org.testng;
|
||||
|
||||
|
||||
import org.testng.collections.Lists;
|
||||
import org.testng.remote.strprotocol.GenericMessage;
|
||||
import org.testng.remote.strprotocol.MessageHelper;
|
||||
import org.testng.xml.XmlSuite;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class IDEARemoteTestNG extends TestNG {
|
||||
|
||||
private static void calculateAllSuites(List<XmlSuite> suites, List<XmlSuite> outSuites) {
|
||||
for (XmlSuite s : suites) {
|
||||
outSuites.add(s);
|
||||
calculateAllSuites(s.getChildSuites(), outSuites);
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
initializeSuitesAndJarFile();
|
||||
|
||||
List<XmlSuite> suites = Lists.newArrayList();
|
||||
calculateAllSuites(m_suites, suites);
|
||||
if(suites.size() > 0) {
|
||||
|
||||
int testCount= 0;
|
||||
|
||||
for(int i= 0; i < suites.size(); i++) {
|
||||
testCount+= (suites.get(i)).getTests().size();
|
||||
}
|
||||
|
||||
GenericMessage gm= new GenericMessage(MessageHelper.GENERIC_SUITE_COUNT);
|
||||
gm.setSuiteCount(suites.size());
|
||||
gm.setTestCount(testCount);
|
||||
// msh.sendMessage(gm);
|
||||
|
||||
addListener((ISuiteListener) new IDEATestNGRemoteListener());
|
||||
addListener((ITestListener) new IDEATestNGRemoteListener());
|
||||
super.run();
|
||||
}
|
||||
else {
|
||||
System.err.println("Nothing found to run");
|
||||
}
|
||||
}
|
||||
catch(Throwable cause) {
|
||||
cause.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package org.testng;
|
||||
|
||||
import jetbrains.buildServer.messages.serviceMessages.ServiceMessage;
|
||||
import jetbrains.buildServer.messages.serviceMessages.ServiceMessageTypes;
|
||||
import org.testng.internal.IResultListener;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 5/22/13
|
||||
*/
|
||||
public class IDEATestNGRemoteListener implements ISuiteListener, IResultListener{
|
||||
public void onConfigurationSuccess(ITestResult itr) {
|
||||
//won't be called
|
||||
}
|
||||
|
||||
public void onConfigurationFailure(ITestResult itr) {
|
||||
//won't be called
|
||||
}
|
||||
|
||||
public void onConfigurationSkip(ITestResult itr) {
|
||||
//won't be called
|
||||
}
|
||||
|
||||
public void onStart(ISuite suite) {
|
||||
System.out.println("##teamcity[testSuiteStarted name =\'" + suite.getName() + "\']");
|
||||
}
|
||||
|
||||
public void onFinish(ISuite suite) {
|
||||
System.out.println("##teamcity[testSuiteFinished name=\'" + suite.getName() + "\']");
|
||||
}
|
||||
|
||||
public void onTestStart(ITestResult result) {
|
||||
System.out.println("##teamcity[testStarted name=\'" + result.getMethod().getMethodName() + "\']");
|
||||
}
|
||||
|
||||
public void onTestSuccess(ITestResult result) {
|
||||
System.out.println("##teamcity[testFinished name=\'" + result.getMethod().getMethodName() + "\']");
|
||||
}
|
||||
|
||||
public String getTrace(Throwable tr) {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
PrintWriter writer = new PrintWriter(stringWriter);
|
||||
tr.printStackTrace(writer);
|
||||
StringBuffer buffer = stringWriter.getBuffer();
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public void onTestFailure(ITestResult result) {
|
||||
final Throwable ex = result.getThrowable();
|
||||
final String trace = getTrace(ex);
|
||||
final Map attrs = new HashMap();
|
||||
attrs.put("name", result.getMethod().getMethodName());
|
||||
final String failureMessage = ex.getMessage();
|
||||
attrs.put("message", failureMessage != null ? failureMessage : "");
|
||||
attrs.put("details", trace);
|
||||
attrs.put("error", "true");
|
||||
System.out.println(ServiceMessage.asString(ServiceMessageTypes.TEST_FAILED, attrs));
|
||||
System.out.println("##teamcity[testFinished name=\'" + result.getMethod().getMethodName() + "\']");
|
||||
}
|
||||
|
||||
public void onTestSkipped(ITestResult result) {
|
||||
System.out.println("##teamcity[testFinished name=\'" + result.getMethod().getMethodName() + "\']");
|
||||
}
|
||||
|
||||
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
|
||||
|
||||
}
|
||||
|
||||
public void onStart(ITestContext context) {
|
||||
|
||||
}
|
||||
|
||||
public void onFinish(ITestContext context) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,8 @@
|
||||
*/
|
||||
package org.testng;
|
||||
|
||||
import com.beust.jcommander.JCommander;
|
||||
import org.testng.remote.RemoteArgs;
|
||||
import org.testng.remote.RemoteTestNG;
|
||||
|
||||
import java.io.*;
|
||||
@@ -27,10 +29,12 @@ import java.lang.reflect.Method;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
public class RemoteTestNGStarter {
|
||||
public static boolean SM_RUNNER = System.getProperty("idea.testng.sm_runner") != null;
|
||||
private static final String SOCKET = "-socket";
|
||||
public static void main(String[] args) throws Exception {
|
||||
int i = 0;
|
||||
@@ -90,6 +94,16 @@ public class RemoteTestNGStarter {
|
||||
reader.close();
|
||||
}
|
||||
|
||||
if (SM_RUNNER) {
|
||||
final IDEARemoteTestNG testNG = new IDEARemoteTestNG();
|
||||
CommandLineArgs cla = new CommandLineArgs();
|
||||
RemoteArgs ra = new RemoteArgs();
|
||||
new JCommander(Arrays.asList(cla, ra), (String[])resultArgs.toArray(new String[resultArgs.size()]));
|
||||
testNG.configure(cla);
|
||||
testNG.run();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
//testng 5.10 do not initialize xml suites before run in normal main call => No test suite found.
|
||||
//revert "cleanup" to set suites manually again, this time for old versions only
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module relativePaths="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_3" inherit-compiler-output="true">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
@@ -8,6 +8,7 @@
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="TestNG" level="project" />
|
||||
<orderEntry type="library" name="tcServiceMessages" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user