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条回答
何必那么认真
2楼-- · 2019-01-18 08:58

These are the two scenarios that the Unrooted errors show up.

  1. If you have missed the annotation @Test before the test.

    @Test

    public void foo(){ }

  2. If it is a Gwt project and when two mock of the same object are defined. Lets say there is one class Class A and

    @GwtMock private A atest;

    @GwtMock private A a; Then this will also show a Unrooted test error.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-01-18 08:59

You are using Hamcrest? or another library to help in your test?. You are not using

import static org.junit.Assert.*;

Check if in your test you use:

import static org.hamcrest.MatcherAssert.assertThat;

or other assert isn´t JUnit assert.

查看更多
够拽才男人
4楼-- · 2019-01-18 09:00

I was getting the "unrooted tests" error message as well and it went away magically. I believe it was due to the fact that I was using Eclipse with a Maven project. When I added a new method to my Test class and gave it the @Test annotation, it began getting the error message when I tried to run that one method using the "Run as Junit test" menu option; however, once I ran a maven build the unrooted tests message disappeared and I believe that is the solution to the problem in the future.

Run a maven build because it will refresh the class that JUnit is using.

查看更多
三岁会撩人
5楼-- · 2019-01-18 09:01

It turned out to be that my build path had some error...some jars were missing. I reconfigured build path and it worked!

查看更多
闹够了就滚
6楼-- · 2019-01-18 09:02

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?

查看更多
啃猪蹄的小仙女
7楼-- · 2019-01-18 09:02

For me this problem was created by a real-time exception thrown in the @AfterClass method (take a look here for documentation):

Basically all the test methods succeeded but at the end of the class this method was failing. Therefore all the tests seems fine but there was on my Eclipse an additional "unrooted test" failed.

查看更多
登录 后发表回答