Run As JUnit not appearing in Eclipse - using JUnit4

巧了我就是萌 提交于 2019-12-12 12:25:03

问题


I'm trying to write JUnit4 tests for my web app, and they had been working fine previously. However, now when I try to run the tests by right clicking the class file -> Run As -> JUnit Test I don't see that option. I think it could be because a colleague committed some Eclipse settings/property files on accident that messed with mine. I'm using Eclipse Helios on a Mac running 10.6.X.

I noticed that the icons on the test classes changed from the "filled" J to a "bubble" J and I'm not sure if that is signifying some kind of problem:

I've double checked and made sure that JUnit4 is on my Build Path, and I've gone to the Eclipse -> Preferences -> JUnit pane and verified there are JUnit4 imports being used.

My test classes look like this:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( { "classpath*:/resources/action-test-appconfig.xml" })
@Transactional
public class UserControllerTest extends BaseStrutsTestCase<UserController> {

    /**
     * Tests the ability of a user to change their login username
     * @throws Exception
     */
    @Test
    public void testChangeLogin() throws Exception {

Any thoughts and suggestions are appreciated.


回答1:


The problem is with the way you are trying to access and run java files in eclipse. You should be observing this empty 'J' icons on your java files. It is a classpath problem, when you click, you are actually accessing the file from the classpath.

To view the Java file, you have to add a reference to your project in the classpath and move it to the top of the classpath list.

Once you do that, then you should be able to run your junits.




回答2:


I had the same issue, and I restarted eclipse and got "Run as JUnit test" back. Looks like a bug in eclipse.




回答3:


Try adding following dependency in the pom.xml of your project in which the test case is located:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>org.springframework.test</artifactId>
        <version>3.1.1.RELEASE</version>
        <scope>test</scope>
    </dependency>



回答4:


That kind of J icon filled to a "bubble" means that Eclipse doesn't recognize your project as a Java project, and therefore doesn't provide Java options such as Run as JUnit.

Try reimporting the project as a Java Project.



来源:https://stackoverflow.com/questions/18149882/run-as-junit-not-appearing-in-eclipse-using-junit4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!