Unrooted Tests

2019-01-18 08:42发布

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.

21条回答
Evening l夕情丶
2楼-- · 2019-01-18 09:19

I had the same problem with java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

you need the jar hamcrest. same question 14539072: java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

查看更多
3楼-- · 2019-01-18 09:20

I got this error because I renamed my test method and then tried to run the test in Eclipse by clicking on the same run configuration - referring to the old method which now didn't exist.

查看更多
别忘想泡老子
4楼-- · 2019-01-18 09:23

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);
  }
}
查看更多
登录 后发表回答