Comments (7)
Sorry for the long delay on this. Unfortunately, I'm having a difficult time pulling up the original SourceForge bugs. Can you give an example test that would pass once this is fixed? Thanks.
from junit4.
No problem, any active work on JUnit is great.
I'll try to find some time during first half of next week to provide such a test.
On 15.04.2011, at 21:57, dsaff wrote:
Sorry for the long delay on this. Unfortunately, I'm having a difficult time pulling up the original SourceForge bugs. Can you give an example test that would pass once this is fixed? Thanks.
Reply to this email directly or view it on GitHub:
https://github.com/KentBeck/junit/issues/38#comment_1010505
from junit4.
This "slightly" overloaded test class contains the items touched by this issue.
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
import org.junit.runner.Request;
import org.junit.runner.Result;
import org.junit.runner.RunWith;
import org.junit.runner.Runner;
import org.junit.runner.manipulation.Filter;
import org.junit.runner.manipulation.NoTestsRemainException;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
public class ParentRunnerFilteringTest {
private static class SingleMethodNameFilter extends Filter {
private String methodName;
public SingleMethodNameFilter(String methodName) {
this.methodName = methodName;
}
@Override
public boolean shouldRun(Description description) {
return description.getMethodName() == null
|| !description.getMethodName().equals(methodName);
}
@Override
public String describe() {
return "filter method name: " + methodName;
}
}
private static class CountingFilter extends Filter {
private final Map<Description, Integer> countMap = new HashMap<Description, Integer>();
@Override
public boolean shouldRun(Description description) {
Integer count = countMap.get(description);
if (count == null) {
countMap.put(description, 1);
} else {
countMap.put(description, count + 1);
}
return true;
}
@Override
public String describe() {
return "filter counter";
}
public void printStats() {
final StringBuffer sb = new StringBuffer();
sb.append("CountingFilter Stats:");
for (Entry<Description, Integer> entry : countMap.entrySet()) {
sb.append("\n");
sb.append("\t");
sb.append(entry.getKey());
sb.append(": ");
sb.append(entry.getValue());
}
System.out.println(sb);
}
public Integer getCount(final Description desc) {
Integer count = null;
if (countMap.containsKey(desc)) {
count = countMap.get(desc);
} else {
boolean found = false;
Iterator<Description> it = countMap.keySet().iterator();
while (!found && it.hasNext()) {
Description curDesc = it.next();
if (curDesc.getDisplayName().equals(desc.getDisplayName())) {
found = true;
count = countMap.get(curDesc);
}
}
}
return count;
}
}
public static class ExampleTest {
@Test
public void test1() throws Exception {
System.out.println("Run: test1");
assertEquals(1, 1);
}
}
@RunWith(Suite.class)
@SuiteClasses({
ExampleTest.class
})
public static class ExampleSuite {
}
@Test
public void testClassFiltering() throws Exception {
Request request = Request.aClass(ExampleTest.class);
Runner runner = request.getRunner();
Filter filter = new SingleMethodNameFilter("test1");
try {
filter.apply(runner);
fail("Expected 'NoTestsRemainException' due to complete filtering");
} catch (NoTestsRemainException e) {
// Expected exception
}
}
@Test
public void testRunClassFiltering() throws Exception {
JUnitCore junitCore = new JUnitCore();
Request request = Request.aClass(ExampleTest.class);
Request requestFiltered = request.filterWith(new SingleMethodNameFilter("test1"));
Result result = junitCore.run(requestFiltered);
assertEquals(1, result.getRunCount());
assertEquals(1, result.getFailureCount());
assertTrue(result.getFailures().get(0).toString().startsWith(
"initializationError(org.junit.runner.manipulation.Filter): No tests found matching filter method name: test1 "));
}
@Test
public void testSuiteFiltering() throws Exception {
Request request = Request.aClass(ExampleSuite.class);
Runner runner = request.getRunner();
assertTrue(runner instanceof Suite);
Suite suite = (Suite) runner;
Filter filter = new SingleMethodNameFilter("test1");
try {
suite.filter(filter);
fail("Expected 'NoTestsRemainException' due to complete filtering"); // TODO: fails here currently
} catch (NoTestsRemainException e) {
// Expected exception
}
}
@Test
public void testSuiteFiltering2() throws Exception {
Request request = Request.aClass(ExampleSuite.class);
Runner runner = request.getRunner();
assertTrue(runner instanceof Suite);
Filter filter = new SingleMethodNameFilter("test1");
try {
filter.apply(runner);
fail("Expected 'NoTestsRemainException' due to complete filtering"); // TODO: fails here currently
} catch (NoTestsRemainException e) {
// Expected exception
}
}
@Test
public void testRunSuiteFiltering() throws Exception {
JUnitCore junitCore = new JUnitCore();
Request request = Request.aClass(ExampleSuite.class);
Request requestFiltered = request.filterWith(new SingleMethodNameFilter("test1"));
Result result = junitCore.run(requestFiltered);
assertEquals(0, result.getRunCount());
assertEquals(0, result.getFailureCount());
}
@Test
public void testCountClassFiltering() throws Exception {
Class<ExampleTest> clazz = ExampleTest.class;
JUnitCore junitCore = new JUnitCore();
Request request = Request.aClass(clazz);
CountingFilter countingFilter = new CountingFilter();
Request requestFiltered = request.filterWith(countingFilter);
Result result = junitCore.run(requestFiltered);
assertEquals(1, result.getRunCount());
assertEquals(0, result.getFailureCount());
countingFilter.printStats();
Description desc = Description.createTestDescription(clazz, "test1");
int count = countingFilter.getCount(desc);
//TODO: now count == 4, but is this reasonably?
assertTrue("Filtering of " + desc + " was called too often: " + count + " times", count < 4); // TODO: fails here currently
}
@Test
public void testCountSuiteFiltering() throws Exception {
Class<ExampleSuite> suiteClazz = ExampleSuite.class;
Class<ExampleTest> clazz = ExampleTest.class;
JUnitCore junitCore = new JUnitCore();
Request request = Request.aClass(suiteClazz);
CountingFilter countingFilter = new CountingFilter();
Request requestFiltered = request.filterWith(countingFilter);
Result result = junitCore.run(requestFiltered);
assertEquals(1, result.getRunCount());
assertEquals(0, result.getFailureCount());
countingFilter.printStats();
Description suiteDesc = Description.createSuiteDescription(clazz);
int suiteCount = countingFilter.getCount(suiteDesc);
//TODO: now count == 4, but is this reasonably?
assertTrue("Filtering of " + suiteDesc + " was called too often: " + suiteCount + " times", suiteCount < 4); // TODO: fails here currently
Description desc = Description.createTestDescription(ExampleTest.class, "test1");
int count = countingFilter.getCount(desc);
//TODO: now count == 9 (!), but is this reasonably?
assertTrue("Filtering of " + desc + " was called too often: " + count + " times", count < 9); // TODO: fails here currently
}
}
from junit4.
Great! Thanks.
On Tue, Apr 19, 2011 at 11:08 AM, reinholdfuereder
[email protected]
wrote:
This "slightly" overloaded test class contains the items touched by this issue.
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
import org.junit.runner.Request;
import org.junit.runner.Result;
import org.junit.runner.RunWith;
import org.junit.runner.Runner;
import org.junit.runner.manipulation.Filter;
import org.junit.runner.manipulation.NoTestsRemainException;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;public class ParentRunnerFilteringTest {
private static class SingleMethodNameFilter extends Filter {
private String methodName;
public SingleMethodNameFilter(String methodName) {
this.methodName = methodName;
}@OverRide
public boolean shouldRun(Description description) {
return description.getMethodName() == null
|| !description.getMethodName().equals(methodName);
}@OverRide
public String describe() {
return "filter method name: " + methodName;
}}
private static class CountingFilter extends Filter {
private final Map<Description, Integer> countMap = new HashMap<Description, Integer>();
@OverRide
public boolean shouldRun(Description description) {
Integer count = countMap.get(description);
if (count == null) {
countMap.put(description, 1);
} else {
countMap.put(description, count + 1);
}
return true;
}@OverRide
public String describe() {
return "filter counter";
}public void printStats() {
final StringBuffer sb = new StringBuffer();
sb.append("CountingFilter Stats:");
for (Entry<Description, Integer> entry : countMap.entrySet()) {
sb.append("\n");
sb.append("\t");
sb.append(entry.getKey());
sb.append(": ");
sb.append(entry.getValue());
}
System.out.println(sb);
}public Integer getCount(final Description desc) {
Integer count = null;
if (countMap.containsKey(desc)) {
count = countMap.get(desc);
} else {
boolean found = false;
Iterator it = countMap.keySet().iterator();
while (!found && it.hasNext()) {
Description curDesc = it.next();
if (curDesc.getDisplayName().equals(desc.getDisplayName())) {
found = true;
count = countMap.get(curDesc);
}
}
}
return count;
}
}public static class ExampleTest {
@test
public void test1() throws Exception {
System.out.println("Run: test1");
assertEquals(1, 1);
}}
@RunWith(Suite.class)
@SuiteClasses({
ExampleTest.class
})
public static class ExampleSuite {}
@test
public void testClassFiltering() throws Exception {
Request request = Request.aClass(ExampleTest.class);
Runner runner = request.getRunner();Filter filter = new SingleMethodNameFilter("test1");
try {
filter.apply(runner);
fail("Expected 'NoTestsRemainException' due to complete filtering");
} catch (NoTestsRemainException e) {
// Expected exception
}
}@test
public void testRunClassFiltering() throws Exception {
JUnitCore junitCore = new JUnitCore();
Request request = Request.aClass(ExampleTest.class);
Request requestFiltered = request.filterWith(new SingleMethodNameFilter("test1"));
Result result = junitCore.run(requestFiltered);
assertEquals(1, result.getRunCount());
assertEquals(1, result.getFailureCount());
assertTrue(result.getFailures().get(0).toString().startsWith(
"initializationError(org.junit.runner.manipulation.Filter): No tests found matching filter method name: test1 "));
}@test
public void testSuiteFiltering() throws Exception {
Request request = Request.aClass(ExampleSuite.class);
Runner runner = request.getRunner();assertTrue(runner instanceof Suite);
Suite suite = (Suite) runner;Filter filter = new SingleMethodNameFilter("test1");
try {
suite.filter(filter);
fail("Expected 'NoTestsRemainException' due to complete filtering"); // TODO: fails here currently
} catch (NoTestsRemainException e) {
// Expected exception
}
}@test
public void testSuiteFiltering2() throws Exception {
Request request = Request.aClass(ExampleSuite.class);
Runner runner = request.getRunner();assertTrue(runner instanceof Suite);
Filter filter = new SingleMethodNameFilter("test1");
try {
filter.apply(runner);
fail("Expected 'NoTestsRemainException' due to complete filtering"); // TODO: fails here currently
} catch (NoTestsRemainException e) {
// Expected exception
}
}@test
public void testRunSuiteFiltering() throws Exception {
JUnitCore junitCore = new JUnitCore();
Request request = Request.aClass(ExampleSuite.class);
Request requestFiltered = request.filterWith(new SingleMethodNameFilter("test1"));
Result result = junitCore.run(requestFiltered);
assertEquals(0, result.getRunCount());
assertEquals(0, result.getFailureCount());
}@test
public void testCountClassFiltering() throws Exception {
Class clazz = ExampleTest.class;JUnitCore junitCore = new JUnitCore();
Request request = Request.aClass(clazz);
CountingFilter countingFilter = new CountingFilter();
Request requestFiltered = request.filterWith(countingFilter);
Result result = junitCore.run(requestFiltered);
assertEquals(1, result.getRunCount());
assertEquals(0, result.getFailureCount());
countingFilter.printStats();Description desc = Description.createTestDescription(clazz, "test1");
int count = countingFilter.getCount(desc);
//TODO: now count == 4, but is this reasonably?
assertTrue("Filtering of " + desc + " was called too often: " + count + " times", count < 4); // TODO: fails here currently
}@test
public void testCountSuiteFiltering() throws Exception {
Class suiteClazz = ExampleSuite.class;
Class clazz = ExampleTest.class;JUnitCore junitCore = new JUnitCore();
Request request = Request.aClass(suiteClazz);
CountingFilter countingFilter = new CountingFilter();
Request requestFiltered = request.filterWith(countingFilter);
Result result = junitCore.run(requestFiltered);
assertEquals(1, result.getRunCount());
assertEquals(0, result.getFailureCount());
countingFilter.printStats();Description suiteDesc = Description.createSuiteDescription(clazz);
int suiteCount = countingFilter.getCount(suiteDesc);
//TODO: now count == 4, but is this reasonably?
assertTrue("Filtering of " + suiteDesc + " was called too often: " + suiteCount + " times", suiteCount < 4); // TODO: fails here currentlyDescription desc = Description.createTestDescription(ExampleTest.class, "test1");
int count = countingFilter.getCount(desc);
//TODO: now count == 9 (!), but is this reasonably?
assertTrue("Filtering of " + desc + " was called too often: " + count + " times", count < 9); // TODO: fails here currently
}}
Reply to this email directly or view it on GitHub:
https://github.com/KentBeck/junit/issues/38#comment_1027251
from junit4.
I took your suggestions, tweaked them, and came up with:
https://github.com/KentBeck/junit/pull/224
I'll push to the master on Monday unless you see something wrong. Thanks.
from junit4.
Great, thanks.
On 29.04.2011, at 20:36, dsaff wrote:
I took your suggestions, tweaked them, and came up with:
https://github.com/KentBeck/junit/pull/224
I'll push to the master on Monday unless you see something wrong. Thanks.
Reply to this email directly or view it on GitHub:
https://github.com/KentBeck/junit/issues/38#comment_1076571
from junit4.
Fixed with https://github.com/KentBeck/junit/commit/01b427b3b89ce04d01f0ddbd746d13a175feec5b
from junit4.
Related Issues (20)
- SpringBoot test failure in circleci HOT 3
- Confusing problem... get differernt result between `main method` and `test method` HOT 7
- Compilation error in org.junit.runner.Result - ObjectInputStream.GetField.get(name, object) throws ClassNotFoundException
- Update to hamcrest 2.2 HOT 16
- Test case grouping - Run subset of test cases depending on specific environment variables HOT 8
- Thread context classloader not reset between tests HOT 1
- Cross site scripting HOT 1
- How to test Redis Time out exception for @Cacheable method with Junit+ Spring integration test HOT 3
- Make Assert failNotEquals public HOT 1
- Assert error messages are not clear HOT 2
- Exception handling of suite() method breaks Jenkins JUnit test history reporting HOT 6
- Add support for "dynamic" default runner selection via system property HOT 8
- When will a new version of junit be released? HOT 1
- JUnitCore could not invoke test HOT 1
- Strange links on "Download and Install" page HOT 1
- junit-4.13.2 compilation error with java 21 HOT 4
- Treat org.opentest4j.TestAbortedException the same as AssumptionViolatedException HOT 4
- Which junit version supports Java 17 ? HOT 2
- Assert check not consistent HOT 9
- Receiving excessively long build DEBUG logs after updating maven-surefire-plugin from 2.22.2 to 3.3.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from junit4.