Search in sources :

Example 21 with SMTestProxy

use of com.intellij.execution.testframework.sm.runner.SMTestProxy in project intellij-community by JetBrains.

the class TestTreeRenderer method customizeCellRenderer.

public void customizeCellRenderer(final JTree tree, final Object value, final boolean selected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) {
    myRow = row;
    myDurationWidth = -1;
    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
    final Object userObj = node.getUserObject();
    if (userObj instanceof SMTRunnerNodeDescriptor) {
        final SMTRunnerNodeDescriptor desc = (SMTRunnerNodeDescriptor) userObj;
        final SMTestProxy testProxy = desc.getElement();
        if (testProxy instanceof SMTestProxy.SMRootTestProxy) {
            SMTestProxy.SMRootTestProxy rootTestProxy = (SMTestProxy.SMRootTestProxy) testProxy;
            if (node.isLeaf()) {
                TestsPresentationUtil.formatRootNodeWithoutChildren(rootTestProxy, this);
            } else {
                TestsPresentationUtil.formatRootNodeWithChildren(rootTestProxy, this);
            }
            if (myAdditionalRootFormatter != null) {
                myAdditionalRootFormatter.format(rootTestProxy, this);
            }
        } else {
            TestsPresentationUtil.formatTestProxy(testProxy, this);
        }
        if (TestConsoleProperties.SHOW_INLINE_STATISTICS.value(myConsoleProperties)) {
            String durationString = testProxy.getDurationString(myConsoleProperties);
            if (durationString != null) {
                durationString = "  " + durationString;
                myDurationWidth = getFontMetrics(getFont()).stringWidth(durationString);
                if (((TestTreeView) myTree).isExpandableHandlerVisibleForCurrentRow(myRow)) {
                    append(durationString);
                }
            }
        }
        //Done
        return;
    }
    //strange node
    final String text = node.toString();
    //no icon
    append(text != null ? text : SPACE_STRING, SimpleTextAttributes.GRAYED_ATTRIBUTES);
}
Also used : SMTRunnerNodeDescriptor(com.intellij.execution.testframework.sm.runner.SMTRunnerNodeDescriptor) SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TestTreeView(com.intellij.execution.testframework.TestTreeView)

Example 22 with SMTestProxy

use of com.intellij.execution.testframework.sm.runner.SMTestProxy in project intellij-community by JetBrains.

the class SMTRunnerFiltersTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    myProperties = createConsoleProperties();
    myResultsViewer = new MockTestResultsViewer(myProperties, mySuite);
    TestConsoleProperties.HIDE_PASSED_TESTS.set(myProperties, false);
    TestConsoleProperties.HIDE_IGNORED_TEST.set(myProperties, false);
    TestConsoleProperties.HIDE_SUCCESSFUL_CONFIG.set(myProperties, true);
    myResultsForm = new SMTestRunnerResultsForm(new JLabel(), myProperties);
    Disposer.register(myResultsForm, myProperties);
    myResultsForm.initUI();
    //setup suites tree
    mySuite.setStarted();
    final SMTestProxy testsSuite = createSuiteProxy("my suite", mySuite);
    testsSuite.setStarted();
    // passed test
    final SMTestProxy testPassed1 = createTestProxy("testPassed1", testsSuite);
    testPassed1.setStarted();
    testPassed1.setFinished();
    // passed config
    final SMTestProxy testConfig1 = createTestProxy("testConfig1", testsSuite);
    testConfig1.setConfig(true);
    testConfig1.setStarted();
    testConfig1.setFinished();
    //ignored test
    final SMTestProxy testIgnored1 = createTestProxy("testIgnored1", testsSuite);
    testIgnored1.setStarted();
    testIgnored1.setTestIgnored("", "");
    testsSuite.setFinished();
    mySuite.setFinished();
}
Also used : SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy)

Example 23 with SMTestProxy

use of com.intellij.execution.testframework.sm.runner.SMTestProxy in project intellij-community by JetBrains.

the class AfterTestEvent method process.

@Override
public void process(@NotNull final TestEventXmlView eventXml) throws TestEventXmlView.XmlParserException {
    final String testId = eventXml.getTestId();
    final String startTime = eventXml.getEventTestResultStartTime();
    final String endTime = eventXml.getEventTestResultEndTime();
    final String exceptionMsg = decode(eventXml.getEventTestResultErrorMsg());
    final String stackTrace = decode(eventXml.getEventTestResultStackTrace());
    final SMTestProxy testProxy = findTestProxy(testId);
    if (testProxy == null)
        return;
    try {
        testProxy.setDuration(Long.valueOf(endTime) - Long.valueOf(startTime));
    } catch (NumberFormatException ignored) {
    }
    final CompositeRunnable runInEdt = new CompositeRunnable();
    final TestEventResult result = TestEventResult.fromValue(eventXml.getTestEventResultType());
    switch(result) {
        case SUCCESS:
            runInEdt.add(testProxy::setFinished);
            break;
        case FAILURE:
            final String failureType = eventXml.getEventTestResultFailureType();
            if ("comparison".equals(failureType)) {
                String actualText = decode(eventXml.getEventTestResultActual());
                String expectedText = decode(eventXml.getEventTestResultExpected());
                final Condition<String> emptyString = StringUtil::isEmpty;
                String filePath = ObjectUtils.nullizeByCondition(decode(eventXml.getEventTestResultFilePath()), emptyString);
                String actualFilePath = ObjectUtils.nullizeByCondition(decode(eventXml.getEventTestResultActualFilePath()), emptyString);
                testProxy.setTestComparisonFailed(exceptionMsg, stackTrace, actualText, expectedText, filePath, actualFilePath);
            } else {
                Couple<String> comparisonPair = parseComparisonMessage(exceptionMsg, "\nExpected: is \"(.*)\"\n\\s*got: \"(.*)\"\n");
                if (comparisonPair == null) {
                    comparisonPair = parseComparisonMessage(exceptionMsg, "\nExpected: is \"(.*)\"\n\\s*but: was \"(.*)\"");
                }
                if (comparisonPair == null) {
                    comparisonPair = parseComparisonMessage(exceptionMsg, "\nExpected: (.*)\n\\s*got: (.*)");
                }
                if (comparisonPair == null) {
                    comparisonPair = parseComparisonMessage(exceptionMsg, "\\s*expected same:<(.*)> was not:<(.*)>");
                }
                if (comparisonPair == null) {
                    comparisonPair = parseComparisonMessage(exceptionMsg, ".*\\s*expected:<(.*)> but was:<(.*)>");
                }
                if (comparisonPair == null) {
                    comparisonPair = parseComparisonMessage(exceptionMsg, "\nExpected: \"(.*)\"\n\\s*but: was \"(.*)\"");
                }
                final Couple<String> finalComparisonPair = comparisonPair;
                runInEdt.add(() -> {
                    if (finalComparisonPair != null) {
                        testProxy.setTestComparisonFailed(exceptionMsg, stackTrace, finalComparisonPair.second, finalComparisonPair.first);
                    } else {
                        testProxy.setTestFailed(exceptionMsg, stackTrace, "error".equals(failureType));
                    }
                });
            }
            runInEdt.add(() -> getResultsViewer().onTestFailed(testProxy));
            break;
        case SKIPPED:
            runInEdt.add(() -> {
                testProxy.setTestIgnored(null, null);
                getResultsViewer().onTestIgnored(testProxy);
            });
            break;
        case UNKNOWN_RESULT:
            break;
    }
    runInEdt.add(() -> getResultsViewer().onTestFinished(testProxy));
    addToInvokeLater(runInEdt);
}
Also used : SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy)

Example 24 with SMTestProxy

use of com.intellij.execution.testframework.sm.runner.SMTestProxy in project intellij-community by JetBrains.

the class DetectClassesToRunTest method testRerunFailedParameterized.

public void testRerunFailedParameterized() throws Exception {
    @SuppressWarnings("TestNGDataProvider") final PsiClass aClass = myFixture.addClass("package a; " + "import org.testng.annotations.DataProvider;\n" + "import org.testng.annotations.Test;\n" + "\n" + "import static org.testng.Assert.assertEquals;\n" + "\n" + "public class ATest {\n" + "\n" + "    @DataProvider\n" + "    public Object[][] testData() {\n" + "        return new Object[][]{\n" + "                {1},\n" + "                {2},\n" + "        };\n" + "    }\n" + "\n" + "    @Test(dataProvider = \"testData\")\n" + "    public void test(int in) {\n" + "        assertEquals(in, 0);\n" + "    }\n" + "}\n");
    final LinkedHashMap<PsiClass, Map<PsiMethod, List<String>>> classes = new LinkedHashMap<>();
    classes.put(aClass, new HashMap<>());
    final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(getProject());
    final SMTestProxy testProxy = new SMTestProxy("test", false, "java:test://a.ATest.test[0]");
    testProxy.setLocator(new JavaTestLocator());
    RerunFailedTestsAction.includeFailedTestWithDependencies(classes, projectScope, getProject(), testProxy);
    final SMTestProxy testProxy2 = new SMTestProxy("test", false, "java:test://a.ATest.test[1]");
    testProxy2.setLocator(new JavaTestLocator());
    RerunFailedTestsAction.includeFailedTestWithDependencies(classes, projectScope, getProject(), testProxy2);
    assertEquals(1, classes.size());
    final Map<PsiMethod, List<String>> params = classes.get(aClass);
    final PsiMethod[] tests = aClass.findMethodsByName("test", false);
    assertContainsElements(params.keySet(), tests);
    final List<String> paramsToRerun = params.get(tests[0]);
    assertEquals(2, paramsToRerun.size());
    assertContainsElements(paramsToRerun, "0", "1");
}
Also used : SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) LinkedHashMap(java.util.LinkedHashMap) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) List(java.util.List) JavaTestLocator(com.intellij.execution.testframework.JavaTestLocator) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 25 with SMTestProxy

use of com.intellij.execution.testframework.sm.runner.SMTestProxy in project intellij-community by JetBrains.

the class TestsPresentationUtilTest method createChildSuiteOfParentSuite.

protected SMTestProxy createChildSuiteOfParentSuite(final String parentName, final String childName) {
    final SMTestProxy parentSuite = createSuiteProxy(parentName);
    final SMTestProxy childSuite = createTestProxy(childName);
    parentSuite.addChild(childSuite);
    return childSuite;
}
Also used : SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy)

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