Skip to content

Commit

Permalink
Failed TestTemplate with only one test doesn't show fail trace
Browse files Browse the repository at this point in the history
This change adjusts TestSuiteElement to show the trace of a failed
child, if that child is the only test case it ran and its dynamic. It
also adjusts navigation to the failed line in this case - so that
navigation goes to the failed line and not to the test method with the
@testtemplate annotation.

Fixes: #1021
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
  • Loading branch information
trancexpress authored and iloveeclipse committed Dec 18, 2023
1 parent 0d3a3cf commit 5c7d1a2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -156,6 +156,15 @@ public String toString() {
return "TestSuite: " + getTestName() + " : " + super.toString() + " (" + fChildren.size() + ")"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}

@Override
public String getTrace() {
TestCaseElement child= getSingleDynamicChild();
if (child != null) {
return child.getTrace();
}
return super.getTrace();
}

private static boolean isSingleDynamicTest(TestElement element) {
if (element instanceof TestCaseElement) {
TestCaseElement testCase = (TestCaseElement) element;
Expand All @@ -166,4 +175,25 @@ private static boolean isSingleDynamicTest(TestElement element) {
}
return false;
}

/**
* If this test suite is a {@code @TestTemplate} test case with a single child, return that child.
* @return The single dynamic test case child or {@code null} if the suite has no children or multiple or non-dynamid children.
*/
public TestCaseElement getSingleDynamicChild() {
try {
if (fChildren.size() == 1) {
TestElement child= fChildren.get(0);
if (child instanceof TestCaseElement) {
TestCaseElement testCase= (TestCaseElement) child;
if (testCase.isDynamicTest()) {
return testCase;
}
}
}
} catch (IndexOutOfBoundsException e) {
// don't care, children changed concurrently
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2022 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -448,10 +448,18 @@ private OpenTestAction getOpenTestAction(TestSuiteElement testSuite) {
String testName= testSuite.getTestName();
ITestElement[] children= testSuite.getChildren();

if (testName.startsWith("[") && testName.endsWith("]") && children.length > 0 && children[0] instanceof TestCaseElement) { //$NON-NLS-1$ //$NON-NLS-2$
if (children.length > 0 && children[0] instanceof TestCaseElement tce && tce.isDynamicTest()) {
// a group of parameterized tests
return new OpenTestAction(fTestRunnerPart, (TestCaseElement) children[0], null);
}
if (children.length == 0) {
// check if we have applied the workaround for: https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/945
TestCaseElement child= testSuite.getSingleDynamicChild();
if (child != null) {
// a parameterized test that ran only one test
return new OpenTestAction(fTestRunnerPart, child, null);
}
}

int index= testName.indexOf('(');
// test factory method
Expand Down

0 comments on commit 5c7d1a2

Please sign in to comment.