[ 
https://jira.codehaus.org/browse/SUREFIRE-974?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=322630#comment-322630
 ] 

Andreas Gudian commented on SUREFIRE-974:
-----------------------------------------

This is why it happens. The junit47 runner uses Filters to do all kinds of 
filtering (groups, method-patterns). And this is, what JUnit makes of it when 
it tries to filter a JUnit3-style test class:

{code|title=org.junit.internal.runners.JUnit38ClassRunner}
public void filter(Filter filter) throws NoTestsRemainException {
    if (getTest() instanceof Filterable) {
        Filterable adapter = (Filterable) getTest();
        adapter.filter(filter);
    } else if (getTest() instanceof TestSuite) {
        TestSuite suite = (TestSuite) getTest();
        TestSuite filtered = new TestSuite(suite.getName());
        int n = suite.testCount();
        for (int i = 0; i < n; i++) {
            Test test = suite.testAt(i);
            if (filter.shouldRun(makeDescription(test))) {
                filtered.addTest(test);
            }
        }
        setTest(filtered);
    }
}
{code}

As you can see, your specific TestCase implementation is dropped and replaced 
by a fresh TestSuite instance, with the filtered tests added.
What you could do in your test is to either just rely on setUp/tearDown to 
perform intialization before/after the tests, or to implement Filterable and 
just do nothing in that implementation ;)

Form the top of my head, I don't see what Surefire could do against that. Any 
suggestions?

                
> Custom junit.framework.TestSuite subtypes ignored when excludedGroups defined
> -----------------------------------------------------------------------------
>
>                 Key: SUREFIRE-974
>                 URL: https://jira.codehaus.org/browse/SUREFIRE-974
>             Project: Maven Surefire
>          Issue Type: Bug
>    Affects Versions: 2.14
>            Reporter: Jesse Glick
>            Assignee: Andreas Gudian
>             Fix For: 2.15
>
>         Attachments: SUREFIRE-974.zip
>
>
> In Jenkins sources @ 919bab8, run:
> {{mvn -f test/pom.xml -Dtest=CoreJellyTest 
> -Dtest.excluded.groups=org.jvnet.hudson.test.FailsOnCloud test}}
> You will get errors from every test case in this suite. When 
> {{test.excluded.groups}} is not defined, it passes.
> This property just sets {{excludedGroups}} for the benefit of some unrelated 
> JUnit 4 tests in the same module which use {{@Category}}. But turning it on 
> apparently changes how JUnit 3 tests are run, too. The named suite has a 
> {{public static Test suite()}} method which creates a subclass of 
> {{TestSuite}} that overrides {{void run(TestResult)}}; when 
> {{excludedGroups}} is defined, a plain {{TestSuite}} is created which fails 
> to set the proper context for test cases and fails utterly.
> Refactoring this test suite to use JUnit 4 idioms is probably not an option 
> at the moment for compatibility reasons. Why is Surefire failing to correctly 
> run JUnit 3 tests just because groups are defined?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to