Ceasar
Ceasar

Reputation: 23083

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.

picture of eclipse with failing tests and no tests in the junittest view

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");
    }

}

Upvotes: 0

Views: 12613

Answers (3)

moilejter
moilejter

Reputation: 998

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 ... :-)

Upvotes: 0

seanhodges
seanhodges

Reputation: 17524

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.

Upvotes: 4

Fabio Kenji
Fabio Kenji

Reputation: 776

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).

Upvotes: 0

Related Questions