6

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:

enter image description here

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.

rawkfist0215
  • 1,445
  • 6
  • 21
  • 34

4 Answers4

10

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.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
  • Sorry, but I'm unfamiliar with doing that. Where would I go to add the reference in the classpath? – rawkfist0215 Aug 09 '13 at 15:30
  • @rawkfist0215 Ok i will give u another way, do this: ctrl+shift+r and type the name of your test class. If you see the list containing more than one entry. Try different entry to open the correct java file. Correct java file will have a filled J icon instead of an empty one. Let me know if this trick works for u. – Juned Ahsan Aug 09 '13 at 15:32
  • 1
    If I ctrl+shift+r and search for the classes they come up with the filled J icon. There is only one entry per class though. Opening them with the search did seem to make the Run As -> JUnit option available, but when I click the option it says "No JUnit tests found" and the empty J icon is still there in the package explorer. – rawkfist0215 Aug 09 '13 at 15:52
  • I was able to solve the issue by adding the folder containing the Test classes as a Source folder in the Build Path. I think this may be what you meant by adding it as a reference on the classpath? – rawkfist0215 Aug 09 '13 at 16:41
  • I am facing this problem. But I cannot get what you were discussing. Could you please show some details on how to solve it? – allenwang Feb 15 '15 at 06:28
  • I imported a project by `File->Import->Existing Projects into Workspace`. But when I right click the package, I could not find **JUnit Test** in the **Run as**. I have been hard on it. Could you please give me some ideas? – allenwang Feb 15 '15 at 06:46
  • Go to the tests folder->build config->use as source folder. This works for me. – Madhurya Gandi Jul 02 '18 at 20:21
8

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

divyaravi
  • 243
  • 3
  • 7
0

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.

Luis Sep
  • 2,384
  • 5
  • 27
  • 33
  • I tried removing the project from my system, rechecking it out from the repository, and then reimporting it as an existing project but unfortunately that did not work. – rawkfist0215 Aug 09 '13 at 16:31
  • But what is ever a Java project? In the first place? When you say that it didn't work, you mean that you couldn't import it or that Eclipse doesn't still recognize as a Java project? – Luis Sep Aug 09 '13 at 18:26
0

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>
Andy
  • 9
  • 1