use of com.intellij.execution.testframework.sm.runner.SMTestProxy in project intellij-community by JetBrains.
the class JUnitOpenSourceAtExceptionTest method testStackTraceParseerAcceptsJavaStacktrace.
public void testStackTraceParseerAcceptsJavaStacktrace() throws Exception {
myFixture.addClass("abstract class ATest extends junit.framework.TestCase {" + " public void testMe() {\n" + " int i = 0;\n" + " int j = 0;\n" + " int k = 0;\n" + " fail();\n" + " }\n" + "}");
myFixture.addClass("public class ChildTest extends ATest {}");
final SMTestProxy testProxy = new SMTestProxy("testMe", false, "java:test://ChildTest.testMe");
testProxy.setTestFailed("failure", "\tat junit.framework.Assert.fail(Assert.java:57)\n" + "\tat junit.framework.Assert.failNotEquals(Assert.java:329)\n" + "\tat junit.framework.Assert.assertEquals(Assert.java:78)\n" + "\tat junit.framework.Assert.assertEquals(Assert.java:234)\n" + "\tat junit.framework.Assert.assertEquals(Assert.java:241)\n" + "\tat junit.framework.TestCase.assertEquals(TestCase.java:409)\n" + "\tat ATest.testMe(Dummy.java:6)\n", true);
final Project project = getProject();
final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
testProxy.setLocator(JavaTestLocator.INSTANCE);
final Location location = testProxy.getLocation(project, searchScope);
assertNotNull(location);
assertInstanceOf(location, MethodLocation.class);
final JUnitConfiguration configuration = new JUnitConfiguration("p", getProject(), JUnitConfigurationType.getInstance().getConfigurationFactories()[0]);
final Navigatable descriptor = testProxy.getDescriptor(location, new JUnitConsoleProperties(configuration, DefaultRunExecutor.getRunExecutorInstance()));
assertInstanceOf(descriptor, OpenFileDescriptor.class);
final OpenFileDescriptor fileDescriptor = (OpenFileDescriptor) descriptor;
final VirtualFile file = fileDescriptor.getFile();
assertNotNull(file);
assertEquals(5, fileDescriptor.getLine());
}
use of com.intellij.execution.testframework.sm.runner.SMTestProxy in project intellij-community by JetBrains.
the class JUnitRerunFailedTestsTest method testParameterizedTestNavigation.
public void testParameterizedTestNavigation() throws Exception {
myFixture.addClass("package org.junit.runner;\n" + "public @interface RunWith {\n" + " Class<? extends Runner> value();\n" + "}");
myFixture.addClass("package org.junit.runners; public class Parameterized {}");
final PsiClass testClass = myFixture.addClass("import org.junit.Test;\n" + "import org.junit.runner.RunWith;\n" + "import org.junit.runners.Parameterized;\n" + "@RunWith(Parameterized.class)\n" + "public class MyTest {\n" + " @Test\n" + " public void testName1() throws Exception {}\n" + "}");
final Project project = getProject();
final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
final JavaTestLocator locationProvider = JavaTestLocator.INSTANCE;
final SMTestProxy rootProxy = new SMTestProxy("MyTest", true, "java:suite://MyTest");
rootProxy.setLocator(locationProvider);
final SMTestProxy proxyParam = new SMTestProxy("[0.java]", true, "java:suite://MyTest.[0.java]");
proxyParam.setLocator(locationProvider);
final SMTestProxy parameterizedTestProxy = new SMTestProxy("testName1[0.java]", false, "java:test://MyTest.testName1[0.java]");
parameterizedTestProxy.setLocator(locationProvider);
final Location rootLocation = rootProxy.getLocation(project, searchScope);
assertNotNull(rootLocation);
assertEquals(testClass, rootLocation.getPsiElement());
final Location proxyParamLocation = proxyParam.getLocation(project, searchScope);
assertNotNull(proxyParamLocation);
assertInstanceOf(proxyParamLocation, PsiMemberParameterizedLocation.class);
assertEquals("[0.java]", ((PsiMemberParameterizedLocation) proxyParamLocation).getParamSetName());
assertEquals(testClass, proxyParamLocation.getPsiElement());
final Location parameterizedTestProxyLocation = parameterizedTestProxy.getLocation(project, searchScope);
assertNotNull(parameterizedTestProxyLocation);
assertInstanceOf(parameterizedTestProxyLocation, PsiMemberParameterizedLocation.class);
assertEquals("[0.java]", ((PsiMemberParameterizedLocation) parameterizedTestProxyLocation).getParamSetName());
assertEquals(testClass.getMethods()[0], parameterizedTestProxyLocation.getPsiElement());
assertEquals(testClass, ((PsiMemberParameterizedLocation) parameterizedTestProxyLocation).getContainingClass());
assertEquals("MyTest,testName1[0.java]", TestMethods.getTestPresentation(parameterizedTestProxy, project, searchScope));
}
use of com.intellij.execution.testframework.sm.runner.SMTestProxy in project intellij-community by JetBrains.
the class JUnitRerunFailedTestsTest method testLocatorForIgnoredClass.
public void testLocatorForIgnoredClass() throws Exception {
PsiClass aClass = myFixture.addClass("@org.junit.Ignore" + "public class TestClass {\n" + " @org.junit.Test" + " public void testFoo() throws Exception {}\n" + "}");
final SMTestProxy testProxy = new SMTestProxy("TestClass", false, "java:test://TestClass.TestClass");
final Project project = getProject();
final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
testProxy.setLocator(JavaTestLocator.INSTANCE);
Location location = testProxy.getLocation(project, searchScope);
assertNotNull(location);
PsiElement element = location.getPsiElement();
assertEquals(aClass, element);
}
use of com.intellij.execution.testframework.sm.runner.SMTestProxy in project intellij-community by JetBrains.
the class TestDiscoveryExtension method attachToProcess.
@Override
protected void attachToProcess(@NotNull final RunConfigurationBase configuration, @NotNull final ProcessHandler handler, @Nullable RunnerSettings runnerSettings) {
if (runnerSettings == null && isApplicableFor(configuration)) {
final String frameworkPrefix = ((JavaTestConfigurationBase) configuration).getFrameworkPrefix();
final String moduleName = ((JavaTestConfigurationBase) configuration).getConfigurationModule().getModuleName();
Disposable disposable = Disposer.newDisposable();
final Alarm processTracesAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, disposable);
final MessageBusConnection connection = configuration.getProject().getMessageBus().connect();
connection.subscribe(SMTRunnerEventsListener.TEST_STATUS, new SMTRunnerEventsAdapter() {
private List<String> myCompletedMethodNames = new ArrayList<>();
@Override
public void onTestFinished(@NotNull SMTestProxy test) {
final SMTestProxy.SMRootTestProxy root = test.getRoot();
if ((root == null || root.getHandler() == handler)) {
final String fullTestName = test.getLocationUrl();
if (fullTestName != null && fullTestName.startsWith(JavaTestLocator.TEST_PROTOCOL)) {
myCompletedMethodNames.add(frameworkPrefix + fullTestName.substring(JavaTestLocator.TEST_PROTOCOL.length() + 3));
if (myCompletedMethodNames.size() > 50) {
final String[] fullTestNames = ArrayUtil.toStringArray(myCompletedMethodNames);
myCompletedMethodNames.clear();
processTracesAlarm.addRequest(() -> processAvailableTraces(fullTestNames, getTracesDirectory(configuration), moduleName, frameworkPrefix, TestDiscoveryIndex.getInstance(configuration.getProject())), 100);
}
}
}
}
@Override
public void onTestingFinished(@NotNull SMTestProxy.SMRootTestProxy testsRoot) {
if (testsRoot.getHandler() == handler) {
processTracesAlarm.cancelAllRequests();
processTracesAlarm.addRequest(() -> {
processAvailableTraces(configuration);
Disposer.dispose(disposable);
}, 0);
connection.disconnect();
}
}
});
}
}
use of com.intellij.execution.testframework.sm.runner.SMTestProxy in project intellij-community by JetBrains.
the class AntImportTest method testAntFormatTest.
public void testAntFormatTest() throws Exception {
String fileText = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + "<testsuites>\n" + " <testsuite errors=\"0\" failures=\"0\" hostname=\"ignore\" id=\"1\" name=\"MyTest\" package=\"a\" skipped=\"0\" tests=\"3\" time=\"0.062\" timestamp=\"2016-10-10T19:25:11\">\n" + " <testcase classname=\"a.MyTest\" name=\"testA1\" time=\"0.002\" />\n" + " <testcase classname=\"a.MyTest\" name=\"testA2\" time=\"0.0\" />\n" + " <testcase classname=\"a.MyTest\" name=\"testA3\" time=\"0.0\" />\n" + " <system-out><![CDATA[]]></system-out>\n" + " <system-err><![CDATA[]]></system-err>\n" + " </testsuite>\n" + "</testsuites>\n";
ImportedToGeneralTestEventsConverter.parseTestResults(() -> new StringReader(fileText), myEventsProcessor);
final List<? extends SMTestProxy> children = myRootNode.getChildren();
assertEquals(1, children.size());
final SMTestProxy suite = children.get(0);
assertEquals("MyTest", suite.getName());
final List<? extends SMTestProxy> tests = suite.getChildren();
assertEquals(3, tests.size());
assertEquals("testA1", tests.get(0).getName());
}
Aggregations