diff --git a/framework/lib/formatter.jar b/framework/lib/formatter.jar index 3de1e0536..9b2760eab 100644 Binary files a/framework/lib/formatter.jar and b/framework/lib/formatter.jar differ diff --git a/framework/lib/formatter/README.md b/framework/lib/formatter/README.md new file mode 100644 index 000000000..dd14ae09b --- /dev/null +++ b/framework/lib/formatter/README.md @@ -0,0 +1,6 @@ +# Custom JUnit test formatter that outputs executed and failing tests, following +# Defects4J's naming conventions for test entries. + +Run ant test to compile and test the formatter implementation. + +Run ant jar to build and deploy the `formatter.jar`. diff --git a/framework/lib/formatter/expected-output.txt b/framework/lib/formatter/expected-output.txt index f781b1a47..5b8491922 100644 --- a/framework/lib/formatter/expected-output.txt +++ b/framework/lib/formatter/expected-output.txt @@ -10,6 +10,7 @@ --- edu.washington.cs.mut.testrunner.junit4.EmptyTestClass --- edu.washington.cs.mut.testrunner.junit4.InitError --- edu.washington.cs.mut.testrunner.junit4.MethodTimeout::test2 +--- edu.washington.cs.mut.testrunner.junit4.ParamTest::testWithParams --- edu.washington.cs.mut.testrunner.junit4.NonJUnitTest --- edu.washington.cs.mut.testrunner.junit4.NotPublicSuite --- edu.washington.cs.mut.testrunner.junit4.SimpleTest::test2 diff --git a/framework/lib/formatter/src/edu/washington/cs/mut/testrunner/Formatter.java b/framework/lib/formatter/src/edu/washington/cs/mut/testrunner/Formatter.java index 8d07a5705..bc5dd2f0d 100644 --- a/framework/lib/formatter/src/edu/washington/cs/mut/testrunner/Formatter.java +++ b/framework/lib/formatter/src/edu/washington/cs/mut/testrunner/Formatter.java @@ -79,13 +79,26 @@ private void handle(Test test, Throwable t) { className = test.getClass().getName(); { - Pattern regexp = Pattern.compile("(.*)\\((.*)\\)\\s*"); + /* + The expected format for failing tests in Defects4J is: + --- [::]. + + In JUnit, a test's String representation is: + (). + + In JUnit, a parameterized test's String representation is: + [](). + + The pattern below extracts only the method name and class name, + stripping the [] part if it exists. + */ + Pattern regexp = Pattern.compile("([^\\[\\(]*)(\\[.*\\])?\\((.*)\\)\\s*"); Matcher match = regexp.matcher(test.toString()); if (match.matches()) { // Class name will equal to junit.framework.Junit4TestCaseFacade if Junit4 // style tests are ran with Junit3 style test runner. if(className.equals("junit.framework.JUnit4TestCaseFacade")) - className = match.group(2); + className = match.group(3); methodName = match.group(1); } } diff --git a/framework/lib/formatter/test/edu/washington/cs/mut/testrunner/junit4/ParamTest.java b/framework/lib/formatter/test/edu/washington/cs/mut/testrunner/junit4/ParamTest.java new file mode 100644 index 000000000..8a7f2a797 --- /dev/null +++ b/framework/lib/formatter/test/edu/washington/cs/mut/testrunner/junit4/ParamTest.java @@ -0,0 +1,36 @@ +package edu.washington.cs.mut.testrunner.junit4; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +@RunWith(Parameterized.class) +public class ParamTest { + + private Integer testNo; + + public ParamTest(Integer n) { + this.testNo = n; + } + + @Parameters + public static Collection params() { + final List list = new ArrayList(3); + list.add(new Integer[] {1}); + list.add(new Integer[] {2}); + list.add(new Integer[] {3}); + return list; + } + + @Test + public void testWithParams() { + assertTrue(false); + } +}