diff --git a/java/java.testrunner/nbproject/project.xml b/java/java.testrunner/nbproject/project.xml index bd9d1d45e138..421c61f202cf 100644 --- a/java/java.testrunner/nbproject/project.xml +++ b/java/java.testrunner/nbproject/project.xml @@ -188,6 +188,7 @@ org.netbeans.modules.junit.ant org.netbeans.modules.junit.ant.ui org.netbeans.modules.junit.ui + org.netbeans.modules.maven.junit.ui org.netbeans.modules.selenium2.java org.netbeans.modules.testng org.netbeans.modules.testng.ant diff --git a/java/junit.ant.ui/src/org/netbeans/modules/junit/ant/ui/AntJUnitNodeOpener.java b/java/junit.ant.ui/src/org/netbeans/modules/junit/ant/ui/AntJUnitNodeOpener.java index 7742482d8225..04f013aa7c62 100644 --- a/java/junit.ant.ui/src/org/netbeans/modules/junit/ant/ui/AntJUnitNodeOpener.java +++ b/java/junit.ant.ui/src/org/netbeans/modules/junit/ant/ui/AntJUnitNodeOpener.java @@ -38,6 +38,7 @@ import org.netbeans.modules.gsf.testrunner.api.CommonUtils; import org.netbeans.modules.gsf.testrunner.ui.api.TestMethodNode; import org.netbeans.modules.gsf.testrunner.ui.api.TestsuiteNode; +import org.netbeans.modules.java.testrunner.JavaRegexpUtils; import org.openide.ErrorManager; import org.openide.filesystems.FileObject; import org.netbeans.modules.junit.api.JUnitTestSuite; @@ -45,7 +46,6 @@ import org.netbeans.modules.java.testrunner.ui.api.NodeOpener; import org.netbeans.modules.java.testrunner.ui.api.UIJavaUtils; import org.netbeans.modules.junit.ui.api.JUnitCallstackFrameNode; -import org.openide.filesystems.FileUtil; import org.openide.nodes.Node; /** @@ -157,6 +157,7 @@ public void openCallstackFrame(Node node, String frameInfo) { } // Method node might belong to an inner class FileObject testfo = methodNode.getTestcase().getClassFileObject(true); + String fqMethodName = methodNode.getTestcase().getClassName() + '.' + methodNode.getTestcase().getName(); if(testfo == null) { return; } @@ -164,22 +165,34 @@ public void openCallstackFrame(Node node, String frameInfo) { FileObject file = UIJavaUtils.getFile(frameInfo, lineNumStorage, locator); //lineNumStorage -1 means no regexp for stacktrace was matched. if ((file == null) && (methodNode.getTestcase().getTrouble() != null) && lineNumStorage[0] == -1) { - //213935 we could not recognize the stack trace line and map it to known file - //if it's a failure text, grab the testcase's own line from the stack. - boolean methodNodeParentOfStackTraceNode = false; String[] st = methodNode.getTestcase().getTrouble().getStackTrace(); if ((st != null) && (st.length > 0)) { - int index = st.length - 1; - //213935 we need to find the testcase linenumber to jump to. + int index = 0;//st.length - 1; + //Jump to the first line matching the fully qualified test method name. // and ignore the infrastructure stack lines in the process - while (!testfo.equals(file) && index != -1 && !methodNodeParentOfStackTraceNode) { - file = UIJavaUtils.getFile(st[index], lineNumStorage, locator); - index = index - 1; - // if frameInfo.isEmpty() == true, user clicked on a failed method node. - // Try to find if the stack trace node is relevant to the method node - if(file != null && frameInfo.isEmpty()) { - methodNodeParentOfStackTraceNode = FileUtil.isParentOf(testfo.getParent(), file); + while (index < st.length) { + if (st[index].contains(fqMethodName)) { + file = UIJavaUtils.getFile(st[index], lineNumStorage, locator); + break; } + index++; + } + // if not found, return top line of stack trace. + if (index == st.length) { + index=0; + for(index=0; index < st.length; index++) { + String trimmed=JavaRegexpUtils.specialTrim(st[index]); + if (trimmed.startsWith(JavaRegexpUtils.CALLSTACK_LINE_PREFIX_CATCH) || + trimmed.startsWith(JavaRegexpUtils.CALLSTACK_LINE_PREFIX )){ + file = UIJavaUtils.getFile(st[index], lineNumStorage, locator); + break; + } + } + } + // if that fails, return the test file object. + if (file == null) { + + file = testfo; } } } diff --git a/java/maven.junit.ui/nbproject/project.xml b/java/maven.junit.ui/nbproject/project.xml index adba7995497c..8780a95581ba 100644 --- a/java/maven.junit.ui/nbproject/project.xml +++ b/java/maven.junit.ui/nbproject/project.xml @@ -60,6 +60,15 @@ 2.0 + + org.netbeans.modules.java.testrunner + + + + 1.17 + + + org.netbeans.modules.gsf.testrunner.ui diff --git a/java/maven.junit.ui/src/org/netbeans/modules/maven/junit/ui/MavenJUnitNodeOpener.java b/java/maven.junit.ui/src/org/netbeans/modules/maven/junit/ui/MavenJUnitNodeOpener.java index d4d36712c3f7..8f82f9dfcd0d 100644 --- a/java/maven.junit.ui/src/org/netbeans/modules/maven/junit/ui/MavenJUnitNodeOpener.java +++ b/java/maven.junit.ui/src/org/netbeans/modules/maven/junit/ui/MavenJUnitNodeOpener.java @@ -39,8 +39,10 @@ import org.netbeans.modules.junit.ui.api.JUnitTestMethodNode; import org.netbeans.modules.java.testrunner.ui.api.NodeOpener; import org.netbeans.modules.java.testrunner.ui.api.UIJavaUtils; +import org.netbeans.modules.java.testrunner.JavaRegexpUtils; import org.netbeans.modules.junit.api.JUnitTestcase; import org.netbeans.modules.junit.ui.api.JUnitCallstackFrameNode; + import org.openide.ErrorManager; import org.openide.filesystems.FileObject; import org.openide.nodes.Children; @@ -146,7 +148,7 @@ public void openTestMethod(final TestMethodNode node) { @Override public void openCallstackFrame(Node node, @NonNull String frameInfo) { - if(frameInfo.isEmpty()) { // user probably clicked on a failed test method node, find failing line within the testMethod using the stacktrace + if (frameInfo.isEmpty()) { // user probably clicked on a failed test method node, find failing line within the testMethod using the stacktrace if (!(node instanceof JUnitTestMethodNode)) { return; } @@ -186,18 +188,18 @@ public void openCallstackFrame(Node node, @NonNull String frameInfo) { FileObject file = UIJavaUtils.getFile(frameInfo, lineNumStorage, locator); //lineNumStorage -1 means no regexp for stacktrace was matched. if (testfo != null && file == null && methodNode.getTestcase().getTrouble() != null && lineNumStorage[0] == -1) { - //213935 we could not recognize the stack trace line and map it to known file + //213935 we could not recognize the stack trace line and map it to known file //if it's a failure text, grab the testcase's own line from the stack. String[] st = methodNode.getTestcase().getTrouble().getStackTrace(); - if ((st != null) && (st.length > 0)) { - int index = st.length - 1; - //213935 we need to find the testcase linenumber to jump to. - // and ignore the infrastructure stack lines in the process - while (!testfo.equals(file) && index != -1) { + for (int index = 0; !testfo.equals(file) && index < st.length; index++) { + String trimmed = JavaRegexpUtils.specialTrim(st[index]); + if (trimmed.startsWith(JavaRegexpUtils.CALLSTACK_LINE_PREFIX_CATCH) + || trimmed.startsWith(JavaRegexpUtils.CALLSTACK_LINE_PREFIX)) { file = UIJavaUtils.getFile(st[index], lineNumStorage, locator); - index -= 1; + break; } } + } // Is this a @Test(expected = *Exception.class) test method that failed? if (file == null && lineNumStorage[0] == -1 && node instanceof MavenJUnitTestMethodNode) {