forked from phoedos/pmd
[test] Improve test method name, display test method
This commit is contained in:
@ -240,6 +240,7 @@ public abstract class RuleTst {
|
||||
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(" @org.junit.Test public void " + test.getTestMethodName() + "() {}");
|
||||
System.out.println();
|
||||
TextRenderer renderer = new TextRenderer();
|
||||
renderer.setWriter(new StringWriter());
|
||||
|
@ -155,6 +155,7 @@ public class TestDescriptor {
|
||||
+ "_"
|
||||
+ getDescription()
|
||||
.replaceAll("\n|\r", "_")
|
||||
.replaceAll("[\\.\\(\\)]|\\s", "_");
|
||||
.replaceAll("[^\\w\\d_$]", "_")
|
||||
.replaceAll("\\s+", "_");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.testframework;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.rule.MockRule;
|
||||
|
||||
public class TestDescriptorTest {
|
||||
@Test
|
||||
public void testMethodName() {
|
||||
Assert.assertEquals("MockRule_1_Name", create("Name"));
|
||||
Assert.assertEquals("MockRule_1_Tests_xyz", create("Tests xyz"));
|
||||
Assert.assertEquals("MockRule_1_Tests_xyz__false_positive_", create("Tests xyz (false positive)"));
|
||||
Assert.assertEquals("MockRule_1_Tests_xyz__123", create("Tests xyz #123"));
|
||||
}
|
||||
|
||||
private String create(String description) {
|
||||
TestDescriptor descriptor = new TestDescriptor("foo", description, 0,
|
||||
new MockRule("MockRule", "desc", "msg", "ruleset"));
|
||||
descriptor.setNumberInDocument(1);
|
||||
return descriptor.getTestMethodName();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user