Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle parameterized unit tests. #604

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified framework/lib/formatter.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions framework/lib/formatter/README.md
Original file line number Diff line number Diff line change
@@ -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`.
1 change: 1 addition & 0 deletions framework/lib/formatter/expected-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
--- <class name>[::<method name>].

In JUnit, a test's String representation is:
<method name>(<class name>).

In JUnit, a parameterized test's String representation is:
<method name>[<params>](<class name>).

The pattern below extracts only the method name and class name,
stripping the [<params>] 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Object[]> params() {
final List<Object[]> list = new ArrayList<Object[]>(3);
list.add(new Integer[] {1});
list.add(new Integer[] {2});
list.add(new Integer[] {3});
return list;
}

@Test
public void testWithParams() {
assertTrue(false);
}
}