aspose file tools*
The moose likes Testing and the fly likes Can't run JUnit 4 test in Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Can Watch "Can New topic
Author

Can't run JUnit 4 test in Eclipse

Ernest Kari
Greenhorn

Joined: Jan 10, 2009
Posts: 5
Hi,

I'm trying to upgrade Eclipse from JUnit 3.8.1 to JUnit 4.8.1. Since I couldn't do it through Help > Software Updates, I downloaded the junit-4.8.1.jar file from the junit.org site, copied the file to the Eclipse plugins directory and updated the JUNIT_HOME classpath variable accordingly:
C:/bea92/workshop92/eclipse/plugins/junit-4.8.1.jar

After these changes I was able to run an JUnit 3.8 version of a simple junit test. However, running an JUnit 4 version of a similar test using annotations did NOT work. When I run it, I get an error shown at the bottom of this posting.

The junit class is very simple and could be run from anyone's PC:
package com.bofa.news.upstream;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

public class SimpleTest {
List<String> msgTasks = null;

@Before
protected void setUp() throws Exception {
msgTasks = new ArrayList<String>();
}

@Test
public void testGetAllUpdates() {
msgTasks.add(new String("Str1"));
msgTasks.add(new String("Str2"));

assertEquals("must be size 2", msgTasks.size(), 2);
}

}


Here's the error trace:
junit.framework.AssertionFailedError: No tests found in com.bofa.news.upstream.SimpleTest
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.TestSuite$1.runTest(TestSuite.java:97)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)



Please note that the tests are executed from within Eclipse version 3.1.2 which is part of the BEA Workshop version 9.2.0.0.


Any help will be greatly appreciated.



- Erik
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You can't just copy arbitrary libraries into the plugins directory and expect things to work--they need to be actual plugins.

In any case, not only do you need the JUnit library, you need a *launcher* that can understand that tests might be specified by annotations. I don't know if you could install a more recent version of the JUnit plugin into such an old version of Eclipse, but I suppose you could try (I anticipate failure, however)--3.1 is *very* old. It might be easier to run them via Ant, or install a real version of Eclipse and run your tests (and write your code etc.--it's *way* better than an ancient 3.1 version) from there.

BTW, please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
Ernest Kari
Greenhorn

Joined: Jan 10, 2009
Posts: 5
David,

Thank you for your reply.

>> I don't know if you could install a more recent version of the JUnit plugin into such an old version of Eclipse, but I suppose you could try.
Is there a way to download the plug-in to a local drive and then apply it? Trying to apply an update by going to Help > Software Updates > Find and Install and then selecting Search for updates of the currently installed features results in this error:
Network connection problems encountered during search.
Unable to access "https://dev2devclub.bea.com/updates/workshop/9.2".
Unable to access site: "https://dev2devclub.bea.com/updates/workshop/9.2" [dev2devclub.bea.com]
Unable to access site: "https://dev2devclub.bea.com/updates/workshop/9.2" [dev2devclub.bea.com]
Unable to access "https://dev2devclub.bea.com/updates/workshop/9.2".
Unable to access site: "https://dev2devclub.bea.com/updates/workshop/9.2" [dev2devclub.bea.com]
Unable to access site: "https://dev2devclub.bea.com/updates/workshop/9.2" [dev2devclub.bea.com]


Thanks,

- Erik
Ernest Kari
Greenhorn

Joined: Jan 10, 2009
Posts: 5
David,

Thank you for your advice to upgrade to a new version of Eclipse. While it is always a challenge and a tough decision to update the software to the latest and greatest when everyone else in the team is using an older version, I took the risk and it did pay off. Now I can run JUnit 4 tests and enjoy the new features of Eclipse!

For those of you who have the Eclipse Workbench that comes with BEA WebLogic version 9.2 do not hesitate to install a new version of Eclipse. It's easy to install and it does recognize your existing workspace, CVS and the app server. Before you do that, as alwyas the case, for your own good backup your exisitng workspace and everything else that is used by Eclipse. Again, I had no problems but a backup should always be done before such a major upgrade.


Good luck!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Glad to hear it worked--the WebLogic shop I worked at abandoned anything but Eclipse (and/or MyEclipse) many years ago; just wasn't worth the headache. Same with WebSphere (for MyEclipse Blue).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't run JUnit 4 test in Eclipse