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 09:03

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

查看更多
爷的心禁止访问
3楼-- · 2019-01-18 09:03

I ran into this problem by not also declaring the test to be static.

查看更多
可以哭但决不认输i
4楼-- · 2019-01-18 09:04

We solved the problem by making sure our test project was built. We had an issue in the build path which would not allow our test class to be compiled. Once we resolved the build path issue, the test compiled and the "new" method was able to be run. So we can assume that "Unrooted" tests also mean that they don't exist in the compiled binary.

查看更多
该账号已被封号
5楼-- · 2019-01-18 09:04

Maybe it's just a logical confusion about the goal of the method. Let's remember:

E.g. correct tagged test method:

@Test
@Transactional
@Rollback(true)
public void testInsertCustomer() {  
    (...)
}

-With Eclipse Junit plugin, You can run that test method using context menu over the method (E.g. at package explorer expanding the class and methods and selecting "testInsertCustomer()" method and from that item selecting "Run as >> JUnit test").

If you forgot "@Test" tag, or simply the method is not a test, but a (private or not) common method for using as utility for the other tests (e.g. "private fillCustomerObject()"), then the method does not require "@Test" tag, and simply you can not run it as a JUnit test!

It's easy that you could create a utility method and later you forgot the real goal of that method, so if you try to run it as a test, JUnit will shout "Unrooted Tests".

查看更多
相关推荐>>
6楼-- · 2019-01-18 09:05

Another scenario that causes this problem was me blindly copy/pasting a method that requires a parameter. i.e.

import org.junit.Test;

public class MyTest {

    @Test
    public void someMethod(String param) {
          // stuff
    }

}

You have a few simple solutions:

  1. define the variable in the specific test method

  2. add it as an instance variable to the test class

  3. create a setup method and annotate it with @Before

查看更多
Rolldiameter
7楼-- · 2019-01-18 09:10

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.

查看更多
登录 后发表回答