简体   繁体   中英

Why isn't JUnit finding my tests?

To clarify, I'm relatively unfamiliar with Java.

I'm writing a class "GobblerClient" to interact with an API, and to test some of my functions I decided to write a few unit tests using JUnit. I've created a bunch of failing tests, and when I go to run them, it appears that JUnit just fails to find them.

测试失败并且在junittest视图中没有测试的日食的图片

Any ideas why JUnit might not be detecting my tests?

EDIT: The tests in full.

package com.gobbler;

import static org.junit.Assert.*;

import org.junit.Test;

public class GobblerClientTest {

    @Test
    public void testDisplay_name() {
        fail("Not yet implemented");
    }

    @Test
    public void testUser_id() {
        fail("Not yet implemented");
    }

    @Test
    public void testAuthenticity_token() {
        fail("Not yet implemented");
    }

    @Test
    public void testClient_key() {
        fail("Not yet implemented");
    }

    @Test
    public void testGobblerClient() {
        fail("Not yet implemented");
    }

    @Test
    public void testAuthenticate() {
        fail("Not yet implemented");
    }

    @Test
    public void testGet_data() {
        fail("Not yet implemented");
    }

    @Test
    public void testSha1hmac() {
        fail("Not yet implemented");
    }

}

The JUnit dialog is empty until you run some tests, it shows the results of the last run.

An easy way to do this is right-click on your class (either in the Package Explorer or the class name in your source code) and select Run As -> JUnit Test

If no tests appear at this point, try again with Run As -> Run Configurations... and in the Run dialog that appears ensure that the "Test runner" drop-down is set to "JUnit 4". If it is set to an earlier version it will not detect your @Test annotations.

Edit: Since you are using Android rather than the standard JVM, you need to perform some additional setup, see my comments.

This just happened to me, in IBM Rational Application Developer 8.5. In my case, it seems the problem was due to my having configured the project with the default JDK (which is IBM's JDK used for WebSphere). Switching to vanilla JDK 1.6 fixed it for me. I suspect the real reason is not the actual version of the JDK - but the switch was good enough to allow me to move on ... :-)

A few guesses: perhaps your Eclipse is already running a previous junit session which got stuck for some reason; pressing "Terminate" and trying again might help.

Another thing you might want to check is your Eclipse version; if it's too old its embedded junit runner might not recognize Junit's annotations, which were included in junit 4.x if I'm not mistaken.

One final guess would be trying to check if the actual junit test is included in your project's build path (although this is very unlikely since you were able to make Eclipse start running your test).

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