2

Hallo,

I have the following situation:

We are developing an Eclipse RCP Application and want to switch from Eclipse 3.4 to Eclipse 3.5. Our JUnit-Tests are using JUnit 4.3.1 and we have a launch configuration to start our test suite. I think I don't need to go into more details here.

The problem is:

Running the tests with Eclipse 3.5 does not work: JUnit cannot find any annotations in the test classes (neither (at)Test nor (at)RunWith).


I patched the junit library with some logging output to check what is going on. I found out that this problem is a classloading issue:

The test class passed to JUnit 'lies in' a ClassLoader which is different from the one JUnit uses to load the annotation classes like 'RunWith'. This is not the case in Eclipse 3.4

in org.junit.internal.requests.ClassRequest:

public Runner getRunner() {   
    log("TestClass     ClassLoader: "+this.fTestClass.getClassLoader());
    log("RunWith.class ClassLoader: "+RunWith.class.getClassLoader());   
    ... // validating test class: searching for annotations and more

}

The first line prints another classloader than the second line. This is bad because JUnit cannot match the annotations in the test class with the Annotation-Class (here: RunWith.class): "RunWith" in CL1 is not equal to "RunWith" in CL2.


I have a solution which points to the core problem: Replace JUnit 4.5 in Eclipse Galileo with JUnit 4.3.1 so that there is only one JUnit-Version: The Test-Run and the tests classes are both using JUnit 4.3.1 (I had to patch "org.eclipse.jdt.junit4.runtime" to accept an ealier junit version).

I think I can also replace JUnit 4.3.1 in my test class with Version 4.5, but that is not an option yet.

Guess: The classloaders are different because the classes 'come from' different JUnit-Bundles: the testclass with its annotations from version 4.3.1 and the test runs in version 4.5

What I want to know: Is there any other solution besides patching Eclipse (replace JUnit versions)? Any commandline argument or such? Any configuration to force Eclipse to Use JUnit 4.3.1?

Any hints on the above described analysis are welcome!

4

1 回答 1

0

我不确定这就是你要找的东西,但是:

在 JUnit 测试的运行配置中,您可以选择要使用的测试运行程序(JUnit 4、JUnit 3...)

于 2009-11-12T22:28:54.503 回答