Priority
Normal
Type
Bug 
State
Won't fix 
Assignee
Anna Kozlova 
Subsystem
Unit Testing. JUnit 
Affected versions
Fixed in
Fixed in build
Next build 
Build
7562
Severity
0
  • Submitted by   Eugene Kirpichov
    2 years ago (21 Nov 2007 16:00)
  • Updated by Eugene Kirpichov
    16 months ago (17 Sep 2008 03:21)
  • Jira: IDEA-16466
    (history, comments)

IDEA-16466

When a JUnit4 test extends TestCase, individual test methods can't be run

0
Added by <no user>
16 Sep 2009
Picture 1.png   (27 KB)

In the following code, when I right-click testB and press "Run testB", the following behaviour happens:
  • All 4 tests are actually run, in the declared order
  • The tree in the Run view shows: testB {SomeTest {testB, testB, testB}} where these 3 testB's correspond to testX, testB and testC.

When I run SomeTest, again all 4 tests are run.

whereas I expect IDEA to detect that it is a JUnit 4 test, not JUnit 3 (despite the fact it inherits TestCase) and process @Ignore annotations accordingly, and of course I expect it to do what I mean by clicking 'run this method'.

I now understand that JUnit 4 and JUnit 3 tests really should not be mixed, but in any case it is definitely a serious bug.

In my code, I inherited Spring's AbstractDependencyInjectionSpringContextTests without thinking that it inherits TestCase, annotated everything with @Test or @Ignore etc. and had a lot of fun trying to figure out why I can't run individual methods and why @Ignore does not work.
Even if I remove the @Test annotations, this bug prevents me from using @Ignore annotations also, simply because I want to use the Spring tests base class.

package ru.jkff.test;

import junit.framework.TestCase;
import org.junit.Test;
public class SomeTest extends TestCase {
    @Test
    public void testA() {
        System.out.println("testA");
    }
    @Test
    @Ignore("X is bad")
    public void testX() {
        System.out.println("testX");
    }
    @Test
    public void testB() {
        System.out.println("testB");
    }
    @Test
    public void testC() {
        System.out.println("testC");
    }
}


Issue was resolved
Comments (6)
 
History (0)
 
Links
 
Anna Kozlova
  Anna Kozlova
05 Dec 2007 15:19
(2 years ago)
#permalink
Without @Test your class is simple TestCase and no annotations are checked
Eugene Kirpichov
  Eugene Kirpichov
05 Dec 2007 15:33
(2 years ago)
#permalink
Well, so what?

I was talking about completely incorrect and unobvious behaviour WITH a @Test; according to your words, with @Test annotations my class is _not_ a simple TestCase and should be processed as a JUnit4 test; but it is processed as a mysterious and buggy mixture of JUnit4 and JUnit3, as I pointed in my bug report.
Anna Kozlova
  Anna Kozlova
05 Dec 2007 15:55
(2 years ago)
#permalink
"I now understand that JUnit 4 and JUnit 3 tests really should not be mixed"
I think that it is an answer for your question.

You can see that 2 command lines (with and without extending TestCase) are the same. Seems that JUnit4 Runner doesn't process correctly mix with JUnit3.

Do you have any suggestions?

Thank you
Eugene Kirpichov
  Eugene Kirpichov
05 Dec 2007 16:03
(2 years ago)
#permalink
I think one could simply write a correct TestRunner. It does not seem like a lot of work :)
K Smith
  K Smith
16 Sep 2008 19:41
(16 months ago)
#permalink
This one is biting me now over code I don't have control to change...

There are 140 test methods in one test class, the are all annotated with @Test, but the class extends a TestCase too. I can't run a single test method by itself. The IDE allows me to but in reality all 140 tests are executed and reported as being the one test I selected.

(Diana build 8792)
Grant Gochnauer
  Grant Gochnauer
17 Sep 2008 03:21
(16 months ago)
#permalink
I've gotten bitten by this as well.

This is especially a problem with extending Spring's JUnit4 abstract test classes and using @Test annotations for methods. In other words you cannot combine the two.