简体   繁体   中英

JUnit 3 and 4 not working on eclipse 4.2

I am trying to learn JUnit and I am not able to make it run. I tried eclipse 4.2 and Android Developer tools (v22). I am setting up a simple project with one test case. I tried with JUnit 4 and 3, but whenever I run the test case as a JUnit test, nothing happens, the console hangs. No output from setup before class, tear down or any method. No results.

Here's a simple screenshot of the project with JUnit 3 (same thing happens with JUnit 4).

在此处输入图片说明

I looked for solutions on the SO and other places but none of them seem to fit my case. The most common problem is multiple JDKs, where in fact I have a single JDK installed, namely 1.7. The second common problem is the inclusion of JUnit libraries in the project. As you can see, the library is in fact included. When I go to the run configuration to check the classpath, I don't see JUnit, like in the following screenshot.

在此处输入图片说明

However, even if I add JUnit to the running classpath in the launch configuration, I still have the same issue.

Is there anything I can do to fix it or see what could be the problem?

Edit: I am on a mac book air running OS X 10.8

Not sure why you are seeing a hang in Eclipse. Perhaps its your Eclipse installation.

More imporantly, when using JUnit 4, you need to annotate your test cases with @Test. Also your setUp and tearDown methods should be annotated with @Before and @After respectively.

Check this post for a very simple JUnit test and brief explanation of the basic annoations.

Here is a re-rewrite of your test...

public class AA {
    @Before
    public void setUp() throws Exception {
        // Runs once before each method annotated with @Test
    }

    @After
    public void tearDown() throws Exception {
        // Runs once after each method annotated with @Test.
    }


    @Test
    public void testZabri() {
        // The Sample Test case
        fail("Not yet implemented");
    }


}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM