views:

2220

answers:

6
+3  Q: 

Unrooted Tests

When running all my tests in Eclipse (Eclipse 3.4 'Ganymede'), one test is listed under "Unrooted Tests". I'm using Junit 3.8 and this particular test extends TestCase. I do not see any difference between this test and the other tests. I don't remember seeing this occur in Eclipse 3.3 (Europa).

Clarification:

We haven't moved to JUnit 4.0 yet, so we are not using annotations. I also googled and it seemed like most people were having issues with JUnit 4, but I did not see any solutions. At this point the test passes both locally and in CruiseControl so I'm not overly concerned, but curious.

When I first saw this, though, it was on a failing test that only failed when run with other tests. This led me down the rabbit hole looking for a solution to the "Unrooted" issue that I never found. Eventually I found the culprit in another test that was not properly tearing down.

I agree, it does seem like an Eclipse issue.

+1  A: 

I've never seen this -- but as far as I can tell from skimming Google for a few minutes, this appears as though it could be a bug in Eclipse rather than a problem with your test. You don't have the @Test annotation on the test, I assume? Can you blow the test away and recreate it, and if so do you get the same error?

Jim Kiley
+4  A: 

I have run into this before as well. I do believe it has to do with JUnit 3/4 discrepancies. Check that your unit tests are running with the appropriate JUnit runner class. See: http://www.nabble.com/what%27s-an-%22Unrooted-Test%22-and-why-can%27t-I-find-anything-online-about-it--td14326290.html

aaron
+4  A: 

If your class extends TestCase somewhere in its hierarchy, you have to use the JUnit 3 test runner listed in the drop down under run configurations. Using the JUnit 4 runner (the default I believe) causes that unrooted test phenomenon to occur.

laz
+3  A: 

Finally I found the solution. The problem is that you are not defining your test cases using annotations but are still doing it the "old way". As soon as you convert over to using annotations you will be able to run one test at a time again.

Here is an example of what a basic test should now look like using annotations:

import static org.junit.Assert.*; // Notice the use of "static" here
import org.junit.Before;
import org.junit.Test;

public class MyTests { // Notice we don't extent TestCases anymore

  @Before
  public void setUp() { // Note: It is not required to call this setUp()
    // ...
  }

  @Test
  public void doSomeTest() { // Note: method need not be called "testXXX"
    // ...
    assertTrue(1 == 1);
  }
}
raiglstorfer
A: 

I could the fix the issue by shifting from TestRunner ver 4.0 to 3 in run configurations for the individual test method.

Krishna Kumar
A: 

Do not extend junit.framework.TestCase in your test class with junit1.4 and this should solve the problem

geo