Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run As JUnit not appearing in Eclipse - using JUnit4

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.

like image 847
rawkfist0215 Avatar asked Aug 09 '13 15:08

rawkfist0215


People also ask

How do I import JUnit into Eclipse?

Step 1: To configure and build JUnit in Eclipse, Open Eclipse, and Create New Project. Step 2: Go to the Java Build Path category and Click on Add External JARs. Step 3: Browse the jar files, select both and click on Open.

How do I change the JUnit runner in Eclipse?

The steps are as below: Project > Properties > Java Build Path > Libraries. Click "Add External JARs..." button at right side --> Select your preferred JUnit jar. Click OK button.


2 Answers

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.

like image 111
Juned Ahsan Avatar answered Sep 24 '22 06:09

Juned Ahsan


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

like image 35
divyaravi Avatar answered Sep 20 '22 06:09

divyaravi