Search in sources :

Example 16 with AbstractTestProxy

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

the class RerunFailedTestsAction method includeFailedTestWithDependencies.

public static void includeFailedTestWithDependencies(Map<PsiClass, Map<PsiMethod, List<String>>> classes, GlobalSearchScope scope, Project project, AbstractTestProxy proxy) {
    final Location location = proxy.getLocation(project, scope);
    if (location != null) {
        final PsiElement element = location.getPsiElement();
        if (element instanceof PsiMethod && element.isValid()) {
            final PsiMethod psiMethod = (PsiMethod) element;
            PsiClass psiClass = psiMethod.getContainingClass();
            if (psiClass != null && psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
                final AbstractTestProxy parent = proxy.getParent();
                final PsiElement elt = parent != null ? parent.getLocation(project, scope).getPsiElement() : null;
                if (elt instanceof PsiClass) {
                    psiClass = (PsiClass) elt;
                }
            }
            TestNGTestObject.collectTestMethods(classes, psiClass, psiMethod.getName(), scope);
            Map<PsiMethod, List<String>> psiMethods = classes.get(psiClass);
            if (psiMethods == null) {
                psiMethods = new LinkedHashMap<>();
                classes.put(psiClass, psiMethods);
            }
            List<String> strings = psiMethods.get(psiMethod);
            if (strings == null || strings.isEmpty()) {
                strings = new ArrayList<>();
            }
            setupParameterName(location, strings);
            psiMethods.put(psiMethod, strings);
        }
    }
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) PsiElement(com.intellij.psi.PsiElement) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) Location(com.intellij.execution.Location)

Example 17 with AbstractTestProxy

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

the class PyTestRunConfiguration method getTestSpec.

@Nullable
@Override
public final String getTestSpec(@NotNull final Location location, @NotNull final AbstractTestProxy failedTest) {
    /**
     *  PyTest supports subtests (with yielding). Such tests are reported as _test_name[index] and location does not point to actual test.
     *  We need to get rid of braces and calculate name manually, since location is incorrect.
     *  Test path starts from file.
     */
    final int indexOfBrace = failedTest.getName().indexOf('[');
    if (indexOfBrace == -1) {
        return super.getTestSpec(location, failedTest);
    }
    final List<String> testNameParts = new ArrayList<>();
    final VirtualFile file = location.getVirtualFile();
    if (file == null) {
        return null;
    }
    final String fileName = file.getName();
    testNameParts.add(failedTest.getName().substring(0, indexOfBrace));
    for (AbstractTestProxy test = failedTest.getParent(); test != null && !test.getName().equals(fileName); test = test.getParent()) {
        testNameParts.add(test.getName());
    }
    testNameParts.add(file.getCanonicalPath());
    return StringUtil.join(Lists.reverse(testNameParts), TEST_NAME_PARTS_SPLITTER);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with AbstractTestProxy

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

the class FlexUnitExecutionTest method checkResults.

private static void checkResults(IXMLElement expectedRoot, AbstractTestProxy actualRoot) {
    assertEquals("Wrong tests run status", expectedRoot.getAttribute("status", null), getStatusTitle(actualRoot.getMagnitude()));
    assertEquals("Wrong tests suites count", expectedRoot.getChildrenCount(), actualRoot.getChildren().size());
    for (int i = 0; i < actualRoot.getChildren().size(); i++) {
        final AbstractTestProxy actualSuite = actualRoot.getChildren().get(i);
        //assertTrue(actualSuite.getName() + " expected to be suite", actualSuite.);
        IXMLElement expectedSuite = getChild(expectedRoot, actualSuite.getName());
        if (expectedSuite == null) {
            fail("Unexpected suite: " + actualSuite.getName());
        }
        assertEquals("Wrong expected node", "suite", expectedSuite.getName());
        assertEquals("Wrong test suite status", expectedSuite.getAttribute("status", null), getStatusTitle(actualSuite.getMagnitude()));
        assertEquals("Wrong tests count in suite " + actualSuite.getName(), expectedSuite.getChildrenCount(), actualSuite.getChildren().size());
        for (int j = 0; j < actualSuite.getChildren().size(); j++) {
            final AbstractTestProxy actualTest = actualSuite.getChildren().get(j);
            //assertTrue(actualSuite.getName() + " expected to be suite", actualSuite.);
            IXMLElement expectedTest = getChild(expectedSuite, actualTest.getName());
            if (expectedTest == null) {
                fail("Unexpected test: " + actualTest.getName());
            }
            assertEquals("Wrong expected node", "test", expectedTest.getName());
            assertEquals("Wrong test " + actualSuite.getName() + "." + actualTest.getName() + "() status", expectedTest.getAttribute("status", null), getStatusTitle(actualTest.getMagnitude()));
            assertEquals("Test children not allowed", 0, expectedTest.getChildrenCount());
            assertEmpty("Test children not expected", actualTest.getChildren());
        }
    }
}
Also used : AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) IXMLElement(net.n3.nanoxml.IXMLElement)

Example 19 with AbstractTestProxy

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

the class FlexUnitExecutionTest method doTest.

private AbstractTestProxy doTest(boolean debugNotRun, FlexUnitRunnerParameters.Scope testScope, String testClassOrPackage, @Nullable String testMethod, @Nullable String projectRoot, @Nullable FlexUnitRunnerParameters.OutputLogLevel outputLogLevel, String... files) throws Exception {
    configureByFiles(projectRoot, files);
    final Ref<IXMLElement> expected = new Ref<>();
    UIUtil.invokeAndWaitIfNeeded((Runnable) () -> WriteAction.run(() -> {
        try {
            Collection<IXMLElement> collection = JSTestUtils.extractXml(myEditor.getDocument(), "testResults");
            assertEquals("Invalid expected structure", 1, collection.size());
            expected.set(collection.iterator().next());
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }));
    UIUtil.invokeAndWaitIfNeeded((Runnable) () -> WriteAction.run(() -> FlexTestUtils.modifyBuildConfiguration(myModule, configuration -> configuration.setTargetPlatform(myTargetPlatform))));
    final RunnerAndConfigurationSettings runnerAndConfigurationSettings = RunManager.getInstance(myProject).createRunConfiguration("test", FlexUnitRunConfigurationType.getFactory());
    final FlexUnitRunConfiguration flexUnitRunConfig = (FlexUnitRunConfiguration) runnerAndConfigurationSettings.getConfiguration();
    final FlexUnitRunnerParameters params = flexUnitRunConfig.getRunnerParameters();
    params.setModuleName(myModule.getName());
    params.setBCName(FlexBuildConfigurationManager.getInstance(myModule).getBuildConfigurations()[0].getName());
    params.setOutputLogLevel(outputLogLevel);
    params.setScope(testScope);
    switch(testScope) {
        case Class:
            params.setClassName(testClassOrPackage);
            break;
        case Method:
            params.setClassName(testClassOrPackage);
            params.setMethodName(testMethod);
            break;
        case Package:
            params.setPackageName(testClassOrPackage);
            break;
        default:
            fail("Unknown scope: " + testScope);
    }
    flexUnitRunConfig.checkConfiguration();
    final ProgramRunner runner = new FlexUnitTestRunner();
    final Executor executor = debugNotRun ? DefaultDebugExecutor.getDebugExecutorInstance() : DefaultRunExecutor.getRunExecutorInstance();
    final ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, runnerAndConfigurationSettings, getProject());
    final Semaphore compilation = new Semaphore();
    compilation.down();
    final Semaphore execution = new Semaphore();
    execution.down();
    final Semaphore startup = new Semaphore();
    final ProcessListener listener = new ProcessListener() {

        @Override
        public void startNotified(ProcessEvent event) {
            startup.up();
        }

        @Override
        public void processTerminated(ProcessEvent event) {
            execution.up();
        }

        @Override
        public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
        }

        @Override
        public void onTextAvailable(ProcessEvent event, Key outputType) {
            System.out.println("FlexUnit: " + event.getText());
        }
    };
    final Ref<ExecutionConsole> executionConsole = new Ref<>();
    ApplicationManager.getApplication().invokeLater(() -> {
        try {
            runner.execute(env, new ProgramRunner.Callback() {

                @Override
                public void processStarted(RunContentDescriptor descriptor) {
                    compilation.up();
                    startup.down();
                    descriptor.getProcessHandler().addProcessListener(listener);
                    executionConsole.set(descriptor.getExecutionConsole());
                }
            });
        } catch (Throwable t) {
            t.printStackTrace();
            fail(t.getMessage());
            compilation.up();
            startup.up();
            execution.up();
        }
    });
    if (!compilation.waitFor(COMPILATION_TIMEOUT * 1000)) {
        fail("Compilation did not succeed in " + COMPILATION_TIMEOUT + " seconds. There was an error or it took too long\n" + FlexCompilerHandler.getInstance(myProject).getLastCompilationMessages());
    }
    if (!startup.waitFor(STARTUP_TIMEOUT * 1000)) {
        fail("Process was not started in " + STARTUP_TIMEOUT + " seconds");
    }
    if (!execution.waitFor(EXECUTION_TIMEOUT * 1000)) {
        fail("Execution did not finish in " + EXECUTION_TIMEOUT + " seconds");
    }
    // give tests tree some time to stabilize
    Thread.sleep(200);
    final AbstractTestProxy testRoot = ((SMTRunnerConsoleView) executionConsole.get()).getResultsViewer().getRoot();
    checkResults(expected.get(), testRoot);
    if (outputLogLevel == null) {
        checkOutput(testRoot, outputLogLevel);
    }
    return testRoot;
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) TargetPlatform(com.intellij.flex.model.bc.TargetPlatform) ServerSocket(java.net.ServerSocket) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ConsoleViewContentType(com.intellij.execution.ui.ConsoleViewContentType) FlexCompilerHandler(com.intellij.lang.javascript.flex.build.FlexCompilerHandler) Semaphore(com.intellij.util.concurrency.Semaphore) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Map(java.util.Map) TestStateInfo(com.intellij.execution.testframework.sm.runner.states.TestStateInfo) FlexUnitRunConfigurationType(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfigurationType) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) Collection(java.util.Collection) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) HyperlinkInfo(com.intellij.execution.filters.HyperlinkInfo) Nullable(org.jetbrains.annotations.Nullable) Printable(com.intellij.execution.testframework.Printable) ProcessListener(com.intellij.execution.process.ProcessListener) SMTRunnerConsoleView(com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) JSTestOptions(com.intellij.lang.javascript.JSTestOptions) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ProcessEvent(com.intellij.execution.process.ProcessEvent) NotNull(org.jetbrains.annotations.NotNull) FlexBuildConfigurationManager(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager) Ref(com.intellij.openapi.util.Ref) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) CodeInsightTestCase(com.intellij.codeInsight.CodeInsightTestCase) WriteAction(com.intellij.openapi.application.WriteAction) JSTestOption(com.intellij.lang.javascript.JSTestOption) FlexModuleType(com.intellij.lang.javascript.flex.FlexModuleType) FlexUnitLibs(com.intellij.flex.util.FlexUnitLibs) HashMap(java.util.HashMap) CompilerProjectExtension(com.intellij.openapi.roots.CompilerProjectExtension) IXMLElement(net.n3.nanoxml.IXMLElement) SocketTimeoutException(java.net.SocketTimeoutException) RunManager(com.intellij.execution.RunManager) ModuleType(com.intellij.openapi.module.ModuleType) FlexTestUtils(com.intellij.flex.util.FlexTestUtils) ThrowableRunnable(com.intellij.util.ThrowableRunnable) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) ProgramRunner(com.intellij.execution.runners.ProgramRunner) FlexUnitRunnerParameters(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters) Key(com.intellij.openapi.util.Key) FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) IOException(java.io.IOException) Executor(com.intellij.execution.Executor) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) JSTestUtils(com.intellij.lang.javascript.JSTestUtils) Printer(com.intellij.execution.testframework.Printer) FlexCompilerProjectConfiguration(com.intellij.lang.javascript.flex.build.FlexCompilerProjectConfiguration) Assert(org.junit.Assert) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessListener(com.intellij.execution.process.ProcessListener) FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) Semaphore(com.intellij.util.concurrency.Semaphore) IXMLElement(net.n3.nanoxml.IXMLElement) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) Ref(com.intellij.openapi.util.Ref) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) FlexUnitRunnerParameters(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) ProgramRunner(com.intellij.execution.runners.ProgramRunner) Key(com.intellij.openapi.util.Key)

Example 20 with AbstractTestProxy

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

the class FlexUnitExecutionTest method doTestLogOutput.

private void doTestLogOutput(boolean debugNotRun, @Nullable FlexUnitRunnerParameters.OutputLogLevel logLevel) throws Exception {
    AbstractTestProxy testRoot = doTest(debugNotRun, FlexUnitRunnerParameters.Scope.Class, "LogOutput", null, null, logLevel, BASE_PATH + "LogOutput.as");
    checkOutput(testRoot, logLevel);
}
Also used : AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy)

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