Search in sources :

Example 11 with AbstractTestProxy

use of com.intellij.execution.testframework.AbstractTestProxy in project intellij-community by JetBrains.

the class SMTRunnerUIActionsHandler method onTestingFinished.

public void onTestingFinished(final TestResultsViewer sender) {
    // select first defect at the end (my be TRACK_RUNNING_TEST was enabled and affects on the fly selection)
    final SMTestProxy testsRootNode = sender.getTestsRootNode();
    if (TestConsoleProperties.SELECT_FIRST_DEFECT.value(myConsoleProperties)) {
        final AbstractTestProxy firstDefect;
        // defects priority:
        // ERROR -> FAILURE -> GENERAL DEFECTIVE NODE
        final List<SMTestProxy> allTests = testsRootNode.getAllTests();
        final AbstractTestProxy firstError = ProxyFilters.ERROR_LEAF.detectIn(allTests);
        if (firstError != null) {
            firstDefect = firstError;
        } else {
            final AbstractTestProxy firstFailure = ProxyFilters.FAILURE_LEAF.detectIn(allTests);
            if (firstFailure != null) {
                firstDefect = firstFailure;
            } else {
                firstDefect = null;
            }
        }
        // select if detected
        if (firstDefect != null) {
            sender.selectAndNotify(firstDefect);
        }
    }
}
Also used : SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy)

Example 12 with AbstractTestProxy

use of com.intellij.execution.testframework.AbstractTestProxy in project intellij-community by JetBrains.

the class AbstractRerunFailedTestsAction method isActive.

private boolean isActive(AnActionEvent e) {
    Project project = e.getProject();
    if (project == null) {
        return false;
    }
    TestFrameworkRunningModel model = getModel();
    if (model == null || model.getRoot() == null) {
        return false;
    }
    Filter filter = getFailuresFilter();
    for (AbstractTestProxy test : model.getRoot().getAllTests()) {
        //noinspection unchecked
        if (filter.shouldAccept(test)) {
            return true;
        }
    }
    return false;
}
Also used : Project(com.intellij.openapi.project.Project) TestFrameworkRunningModel(com.intellij.execution.testframework.TestFrameworkRunningModel) Filter(com.intellij.execution.testframework.Filter) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy)

Example 13 with AbstractTestProxy

use of com.intellij.execution.testframework.AbstractTestProxy in project intellij-community by JetBrains.

the class ViewAssertEqualsDiffAction method openDiff.

public static boolean openDiff(DataContext context, @Nullable DiffHyperlink currentHyperlink) {
    final AbstractTestProxy testProxy = AbstractTestProxy.DATA_KEY.getData(context);
    final Project project = CommonDataKeys.PROJECT.getData(context);
    if (testProxy != null) {
        DiffHyperlink diffViewerProvider = testProxy.getDiffViewerProvider();
        if (diffViewerProvider != null) {
            final List<DiffHyperlink> providers = collectAvailableProviders(TestTreeView.MODEL_DATA_KEY.getData(context));
            int index = currentHyperlink != null ? providers.indexOf(currentHyperlink) : -1;
            if (index == -1)
                index = providers.indexOf(diffViewerProvider);
            new MyDiffWindow(project, providers, Math.max(0, index)).show();
            return true;
        }
    }
    if (currentHyperlink != null) {
        new MyDiffWindow(project, currentHyperlink).show();
        return true;
    }
    return false;
}
Also used : Project(com.intellij.openapi.project.Project) DiffHyperlink(com.intellij.execution.testframework.stacktrace.DiffHyperlink) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy)

Example 14 with AbstractTestProxy

use of com.intellij.execution.testframework.AbstractTestProxy in project intellij-community by JetBrains.

the class GradleRerunFailedTestsAction method getRunProfile.

@Nullable
@Override
protected MyRunProfile getRunProfile(@NotNull ExecutionEnvironment environment) {
    ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) myConsoleProperties.getConfiguration();
    final List<AbstractTestProxy> failedTests = getFailedTests(configuration.getProject());
    return new MyRunProfile(configuration) {

        @NotNull
        @Override
        public Module[] getModules() {
            return Module.EMPTY_ARRAY;
        }

        @Nullable
        @Override
        public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
            ExternalSystemRunConfiguration runProfile = ((ExternalSystemRunConfiguration) getPeer()).clone();
            Project project = runProfile.getProject();
            Set<String> scriptParameters = ContainerUtil.newLinkedHashSet();
            Set<String> tasksToRun = ContainerUtil.newLinkedHashSet();
            boolean useResolvedTasks = true;
            for (AbstractTestProxy test : failedTests) {
                if (test instanceof GradleSMTestProxy) {
                    String testName = test.getName();
                    String className = ((GradleSMTestProxy) test).getClassName();
                    scriptParameters.add(TestMethodGradleConfigurationProducer.createTestFilter(className, testName));
                    if (!useResolvedTasks)
                        continue;
                    if (className == null) {
                        useResolvedTasks = false;
                        continue;
                    }
                    final PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.projectScope(project));
                    if (psiClass == null) {
                        useResolvedTasks = false;
                        continue;
                    }
                    final PsiFile psiFile = psiClass.getContainingFile();
                    if (psiFile == null) {
                        useResolvedTasks = false;
                        continue;
                    }
                    final Module moduleForFile = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(psiFile.getVirtualFile());
                    if (moduleForFile == null) {
                        useResolvedTasks = false;
                        continue;
                    }
                    ContainerUtil.addAllNotNull(tasksToRun, GradleTestRunConfigurationProducer.getTasksToRun(moduleForFile));
                }
            }
            runProfile.getSettings().setScriptParameters(StringUtil.join(scriptParameters, " "));
            if (useResolvedTasks && !tasksToRun.isEmpty()) {
                runProfile.getSettings().setTaskNames(ContainerUtil.newArrayList(tasksToRun));
            }
            return runProfile.getState(executor, environment);
        }
    };
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) GradleSMTestProxy(org.jetbrains.plugins.gradle.execution.test.runner.GradleSMTestProxy) PsiClass(com.intellij.psi.PsiClass) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) Executor(com.intellij.execution.Executor) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with AbstractTestProxy

use of com.intellij.execution.testframework.AbstractTestProxy in project intellij-community by JetBrains.

the class RerunFailedTestsAction method getRunProfile.

@Override
protected MyRunProfile getRunProfile(@NotNull ExecutionEnvironment environment) {
    final TestNGConfiguration configuration = (TestNGConfiguration) myConsoleProperties.getConfiguration();
    final List<AbstractTestProxy> failedTests = getFailedTests(configuration.getProject());
    return new MyRunProfile(configuration) {

        @Override
        @NotNull
        public Module[] getModules() {
            return configuration.getModules();
        }

        @Override
        public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) {
            return new TestNGRunnableState(env, configuration) {

                @Override
                public SearchingForTestsTask createSearchingForTestsTask() {
                    return new SearchingForTestsTask(myServerSocket, getConfiguration(), myTempFile) {

                        @Override
                        protected void fillTestObjects(final Map<PsiClass, Map<PsiMethod, List<String>>> classes) throws CantRunException {
                            final HashMap<PsiClass, Map<PsiMethod, List<String>>> fullClassList = ContainerUtil.newHashMap();
                            super.fillTestObjects(fullClassList);
                            for (final PsiClass aClass : fullClassList.keySet()) {
                                if (!ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {

                                    @Override
                                    public Boolean compute() {
                                        return TestNGUtil.hasTest(aClass);
                                    }
                                })) {
                                    classes.put(aClass, fullClassList.get(aClass));
                                }
                            }
                            final GlobalSearchScope scope = getConfiguration().getConfigurationModule().getSearchScope();
                            final Project project = getConfiguration().getProject();
                            for (final AbstractTestProxy proxy : failedTests) {
                                ApplicationManager.getApplication().runReadAction(() -> includeFailedTestWithDependencies(classes, scope, project, proxy));
                            }
                        }
                    };
                }
            };
        }
    };
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) PsiMethod(com.intellij.psi.PsiMethod) TestNGConfiguration(com.theoryinpractice.testng.configuration.TestNGConfiguration) PsiClass(com.intellij.psi.PsiClass) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) Executor(com.intellij.execution.Executor) TestNGRunnableState(com.theoryinpractice.testng.configuration.TestNGRunnableState) SearchingForTestsTask(com.theoryinpractice.testng.configuration.SearchingForTestsTask) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module) Computable(com.intellij.openapi.util.Computable)

Aggregations

AbstractTestProxy (com.intellij.execution.testframework.AbstractTestProxy)21 Project (com.intellij.openapi.project.Project)6 PsiClass (com.intellij.psi.PsiClass)5 Nullable (org.jetbrains.annotations.Nullable)4 Executor (com.intellij.execution.Executor)3 Location (com.intellij.execution.Location)3 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)3 PsiElement (com.intellij.psi.PsiElement)3 NotNull (org.jetbrains.annotations.NotNull)3 DiffHyperlink (com.intellij.execution.testframework.stacktrace.DiffHyperlink)2 Module (com.intellij.openapi.module.Module)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiMethod (com.intellij.psi.PsiMethod)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 ArrayList (java.util.ArrayList)2 IXMLElement (net.n3.nanoxml.IXMLElement)2 CodeInsightTestCase (com.intellij.codeInsight.CodeInsightTestCase)1 CoverageDataManager (com.intellij.coverage.CoverageDataManager)1 CoverageSuitesBundle (com.intellij.coverage.CoverageSuitesBundle)1 RunManager (com.intellij.execution.RunManager)1