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:
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.
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.
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.
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.
I had the same issue, and I restarted eclipse and got "Run as JUnit test" back. Looks like a bug in eclipse.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With