Search in sources :

Example 1 with SearchingForTestsTask

use of com.theoryinpractice.testng.configuration.SearchingForTestsTask in project intellij-community by JetBrains.

the class TestNGTestDiscoveryRunnableState method createSearchingForTestsTask.

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

        @Override
        protected void search() throws CantRunException {
            myClasses.clear();
            final TestData data = getConfiguration().getPersistantData();
            final Pair<String, String> position = data.TEST_OBJECT.equals(TestType.SOURCE.getType()) ? Pair.create(data.getMainClassName(), data.getMethodName()) : null;
            final Set<String> patterns = TestDiscoverySearchHelper.search(getProject(), position, data.getChangeList(), getConfiguration().getFrameworkPrefix());
            final Module module = getConfiguration().getConfigurationModule().getModule();
            final GlobalSearchScope searchScope = module != null ? GlobalSearchScope.moduleWithDependenciesScope(module) : GlobalSearchScope.projectScope(getProject());
            TestNGTestPattern.fillTestObjects(myClasses, patterns, TestSearchScope.MODULE_WITH_DEPENDENCIES, getConfiguration(), searchScope);
        }

        @Override
        protected void onFound() {
            super.onFound();
            writeClassesPerModule(myClasses);
        }
    };
}
Also used : SearchingForTestsTask(com.theoryinpractice.testng.configuration.SearchingForTestsTask) TestData(com.theoryinpractice.testng.model.TestData) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module)

Example 2 with SearchingForTestsTask

use of com.theoryinpractice.testng.configuration.SearchingForTestsTask 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

Module (com.intellij.openapi.module.Module)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 SearchingForTestsTask (com.theoryinpractice.testng.configuration.SearchingForTestsTask)2 Executor (com.intellij.execution.Executor)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 AbstractTestProxy (com.intellij.execution.testframework.AbstractTestProxy)1 Project (com.intellij.openapi.project.Project)1 Computable (com.intellij.openapi.util.Computable)1 PsiClass (com.intellij.psi.PsiClass)1 PsiMethod (com.intellij.psi.PsiMethod)1 TestNGConfiguration (com.theoryinpractice.testng.configuration.TestNGConfiguration)1 TestNGRunnableState (com.theoryinpractice.testng.configuration.TestNGRunnableState)1 TestData (com.theoryinpractice.testng.model.TestData)1 NotNull (org.jetbrains.annotations.NotNull)1