From: SourceForge.net <no...@so...> - 2007-07-02 19:54:37
|
Bugs item #1739095, was opened at 2007-06-18 10:18 Message generated for change (Comment added) made by dsaff You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=115278&aid=1739095&group_id=15278 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: test runner Group: None >Status: Pending Resolution: None Priority: 5 Private: No Submitted By: Michael Schechter (javabard) Assigned to: Nobody/Anonymous (nobody) Summary: Filtering does not appear to work in 4.3.1 Initial Comment: NOTE: This bug is being entered at the request of David Saff, as per message #19459 in the JUnit Yahoo group. Please let me know if you have any questions. I have been successfully using a filter implementation that I provided with one or more method names. These methods were the only ones executed in the test class. This worked seamlessly with 4.1. The implementation is designed to allow the test names to be passed to the main() method, emulating the JUnit 3.8.1 functionality that allowed the specification of test names for execution. This is an exceedingly useful tool when trying to nail down a bug that only occurs in one test scenario. I just recently updated to JUnit 4.3.1, and the filter implementation no longer seems to be applied. There is nothing I can find in the release notes that implies that this would have changed. The frustrating thing is that setting breakpoints in my filter has no effect - it is as if it is never being called. I am including the filter implementation class and the invocation logic. ------------------------------------------------ import java.util.ArrayList; import java.util.List; import org.junit.runner.Description; import org.junit.runner.manipulation.Filter; /** * This class provides a mechanism to filter tests by name, allowing a subset of the tests in a test * class to be defined by a developer. * * @since 2.0 */ public class MatchingFilter extends Filter { /** * The references to the tests that should be executed. */ private List<Description> tests = new ArrayList<Description>(); /** * Initializes an instance of <code>MatchingFilter</code> with the data provided. * * @param aTestClass * the class for which tests will be executed * @param someTestNames * the method names */ public MatchingFilter(Class aTestClass, String[] someTestNames) { for (String testName : someTestNames) { this.tests.add(Description.createTestDescription(aTestClass, testName)); } } /** * Implemented abstract method to provide detail filtering mechanism. Only test methods that match * the provided names will be executed. * * @see org.junit.runner.manipulation.Filter#shouldRun(org.junit.runner.Description) */ @Override public boolean shouldRun(Description aDescription) { return this.tests.contains(aDescription); } /** * Implemented abstract method. * * @see org.junit.runner.manipulation.Filter#describe() */ @Override public String describe() { return "This filter excludes any test methods that do not exactly match the provided names"; } } ******************** Invocation logic ******************** ------------------------------------------------ JUnitCore core = new JUnitCore(); Request testRequest = Request.aClass(aTestClass); if (0 < someArguments.length) { Filter matchFilter = new MatchingFilter(aTestClass, someArguments); testRequest = testRequest.filterWith(matchFilter); } core.run(testRequest); ---------------------------------------------------------------------- >Comment By: David Saff (dsaff) Date: 2007-07-02 15:54 Message: Logged In: YES user_id=325156 Originator: NO Michael, Thanks for the report. We tried looking into this, but we can't seem to replicate the problem. For example, this test passes on our latest checkout: public class FilterTest { public static class ShouldFilter { @Test public void testA() {} @Test public void testB() {} } @Test public void filtersWork() { Request request = Request.aClass(ShouldFilter.class).filterWith( new MatchingFilter(ShouldFilter.class, new String[] { "testA" })); Result result = new JUnitCore().run(request); assertEquals(1, result.getRunCount()); } } Does it fail for you? Can you post a different test that fails? Thanks! ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=115278&aid=1739095&group_id=15278 |