Search in sources :

Example 36 with SMTestProxy

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());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) JUnitConsoleProperties(com.intellij.execution.junit2.ui.properties.JUnitConsoleProperties) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location) Navigatable(com.intellij.pom.Navigatable)

Example 37 with SMTestProxy

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));
}
Also used : Project(com.intellij.openapi.project.Project) SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) JavaTestLocator(com.intellij.execution.testframework.JavaTestLocator) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location)

Example 38 with SMTestProxy

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);
}
Also used : SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location)

Example 39 with SMTestProxy

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();
                }
            }
        });
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) Alarm(com.intellij.util.Alarm) ArrayList(java.util.ArrayList) SMTRunnerEventsAdapter(com.intellij.execution.testframework.sm.runner.SMTRunnerEventsAdapter) JavaTestConfigurationBase(com.intellij.execution.JavaTestConfigurationBase)

Example 40 with SMTestProxy

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());
}
Also used : SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) StringReader(java.io.StringReader)

Aggregations

SMTestProxy (com.intellij.execution.testframework.sm.runner.SMTestProxy)42 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)9 Project (com.intellij.openapi.project.Project)8 Location (com.intellij.execution.Location)6 PsiClass (com.intellij.psi.PsiClass)6 MethodLocation (com.intellij.execution.junit2.info.MethodLocation)5 PsiMemberParameterizedLocation (com.intellij.execution.junit2.PsiMemberParameterizedLocation)4 PsiElement (com.intellij.psi.PsiElement)4 PsiMethod (com.intellij.psi.PsiMethod)4 JavaTestLocator (com.intellij.execution.testframework.JavaTestLocator)3 List (java.util.List)3 AbstractTestProxy (com.intellij.execution.testframework.AbstractTestProxy)2 SMTRunnerTreeStructure (com.intellij.execution.testframework.sm.runner.SMTRunnerTreeStructure)2 Ref (com.intellij.openapi.util.Ref)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 NotNull (org.jetbrains.annotations.NotNull)2 ExecutionException (com.intellij.execution.ExecutionException)1 JavaTestConfigurationBase (com.intellij.execution.JavaTestConfigurationBase)1