forked from phoedos/pmd
[test] Print Test Method Name for failed rule tests
This helps to select just this failed test to rerun it within the IDE. Also replace parenthesis in the test case description.
This commit is contained in:
@ -42,6 +42,8 @@ public class PMDTestRunner extends Runner implements Filterable, Sortable {
|
||||
private final RuleTestRunner ruleTests;
|
||||
private final ParentRunner<?> unitTests;
|
||||
|
||||
private final Description description;
|
||||
|
||||
public PMDTestRunner(final Class<? extends SimpleAggregatorTst> klass) throws InitializationError {
|
||||
this.klass = klass;
|
||||
ruleTests = new RuleTestRunner(klass);
|
||||
@ -51,6 +53,8 @@ public class PMDTestRunner extends Runner implements Filterable, Sortable {
|
||||
} else {
|
||||
unitTests = new EmptyRunner(klass);
|
||||
}
|
||||
|
||||
this.description = createDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -76,6 +80,10 @@ public class PMDTestRunner extends Runner implements Filterable, Sortable {
|
||||
|
||||
@Override
|
||||
public Description getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
private Description createDescription() {
|
||||
Description description = Description.createSuiteDescription(klass);
|
||||
description.addChild(createChildrenDescriptions(ruleTests, "Rule Tests"));
|
||||
if (ruleTests.hasUnitTests()) {
|
||||
|
@ -47,10 +47,7 @@ public class RuleTestRunner extends ParentRunner<TestDescriptor> {
|
||||
protected Description describeChild(TestDescriptor testCase) {
|
||||
Description description = testDescriptions.get(testCase);
|
||||
if (description == null) {
|
||||
description = Description.createTestDescription(getTestClass().getJavaClass(),
|
||||
testCase.getRule().getName() + "::"
|
||||
+ testCase.getNumberInDocument() + " "
|
||||
+ testCase.getDescription().replaceAll("\n|\r", " "));
|
||||
description = Description.createTestDescription(getTestClass().getJavaClass().getName(), testCase.getTestMethodName());
|
||||
testDescriptions.putIfAbsent(testCase, description);
|
||||
}
|
||||
return description;
|
||||
|
@ -239,6 +239,7 @@ public abstract class RuleTst {
|
||||
+ " problem(s) found.");
|
||||
System.out.println(" -> Expected messages: " + test.getExpectedMessages());
|
||||
System.out.println(" -> Expected line numbers: " + test.getExpectedLineNumbers());
|
||||
System.out.println("Test Method Name: " + test.getTestMethodName());
|
||||
System.out.println();
|
||||
TextRenderer renderer = new TextRenderer();
|
||||
renderer.setWriter(new StringWriter());
|
||||
|
@ -148,4 +148,15 @@ public class TestDescriptor {
|
||||
public boolean isUseAuxClasspath() {
|
||||
return useAuxClasspath;
|
||||
}
|
||||
|
||||
public String getTestMethodName() {
|
||||
String methodName = getRule().getName() + "_"
|
||||
+ getNumberInDocument()
|
||||
+ "_"
|
||||
+ getDescription()
|
||||
.replaceAll("\n|\r", "_")
|
||||
.replaceAll("[\\(\\)]|\\s", "_");
|
||||
|
||||
return methodName;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user