JUnit test outside eclipse [duplicate] - eclipse

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
JUnit test equivalent in CLI
I have created a java project in eclipse. I am able to right click and export the project to and executable jar file so it can be run from the command line using the JRE tools.
For this same project I also have Junit tests. Specifically I am using JUnit version 4. How can I run the JUnit tests from the command line like I can in eclipse (Right Click Project-->Run As-->JUnit Test)

It is best to use some project management tool such as Maven or Ant (for small projects). This way you'd get IDE independent project with capability to build and run tests outside of the IDE of your choice.

Related

Eclipse cannot run JUnit 5 test cases in JUnit suite?

I've got working junit test cases I'd like to run in an Eclipse test suite. However, Eclipse only seems to have test suite support for JUnit 4 and 3.
It seems my options are to either either downgrade my test cases (which I'm unsure how to do) or upgrade the test suites as well (which I can't seem to find an option for).
Any help?
EDIT: For clarity, I'm working on the latest Eclipse Photon version, just downloaded it two days ago.
With a plain Photon (Java Developers flavour) install, follow these steps to get a working simple eclipse project with a JUnit5 test and a suite containing this test.
On project creation or in the project properties, add JUnit5 as library
Add your tests, run them
Add a test suite (the new Test Suite wizard is lacking the option to create a JUnit5 Suite, you'd need to write it by hand - was that what you were asking?)
In package explorer, do right click on a project and,
Click 'Build Path'
Click 'Add Libraries'
Click on 'JUnit 5' in the list and next, finish.
Then run the tests again.

Run sequel of run configurations in Eclipse

I work on web applications with eclipse which means each time I modify server side code I have to run maven clean install then start my server again. I have run configurations for these both steps in eclipse but need to wait for the first one to finish before starting the second one.
I have also other cases when I need to run maven clean install on 5 or 6 projects in a given order after having updated all of them.
So my question is: does anybody know how to define sequels of runs and run them in the right order on one click in Eclipse (i'm using Indigo). I didn't found any plugin nor help on my favorite search engine.
You can write an Ant-script which wraps the Maven commands (with using Maven Ant Tasks) in the correct order. Then you can create a launch configuration for that Ant script in Eclipse.
Or just write a shell script and create an launch configuration for that in Eclipse.

How to integrate Junit plugin into my custom plug in? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Call JUnit from other Eclipse Plugin
In my Eclipse custom plugin, I can do the unit test with junit. I want to show the results on Junit plugin's view. How to call code in Junit plugin in my custom plugin? Thanks.
Either create a TestSuite and fake out the tests to generate your desired output or try to reuse the console part of the junit plugin.
otherwise your only other choice is to patch the junit plugin which is not recommended because you can screw up the plugin and it is difficult to garauntee will run the same on all versions of eclipse.

Can eclipse be used to fully replace ant?

I don't want to build the files manually with command line,
is it possible for eclipse to do the equivalent for tomcat automatically?
eclipse by default does compile your project automatically. Do you mean to have eclipse deploying to tomcat automatically?
If that is what you would like to do, Eclipse WebTools has support for deploying to servlet container. One example of how to do that is http://www.ibm.com/developerworks/opensource/library/os-eclipse-tomcat/index.html
If you have a build.xml file in your project root, you can right click on it in eclipse, select Run As -> Ant Build...
From there you can configure how it should run the script just as if you were using ant.
Question title
Can eclipse be used to fully replace ant?
Short answer: Do not compare apples with oranges.
Eclipse IDE (Building is one of its feature). Wiki
Ant Build tool. Wiki
Tomcat Webserver. Wiki

Why is Eclipse using JUnit 3 when I have junit-4.3.1.jar in my build path?

I'm using Ganymede on Ubuntu Linux and I have junit-4.3.1.jar in my build path. I click File > New > Java > "JUnit 4 Test Case" when I create a new test, but when it's run, Eclipse appears to be using JUnit 3. I believe this is the case because it's ignoring my annotations.
When I remove all test* methods, JUnit complains "No tests found". If I do the same with another test I already created, JUnit runs fine and finds my test named createTask(). So, it appears to be using JUnit 3 at times, and JUnit 4 at others.
How do I force Eclipse Ganymede to use JUnit 4?
I figured out the answer via this link:
Spring is apparently incompatible with JUnit 4.3.1 when extending AbstractTransactionalSpringDataSourceTest (or whatever it is). So, I upgraded to JUnit 4.6 (b/c 4.5 has issues) and used the annotation-based configuration, and voila, all is well.
Thank you.
I have 2 suggestions that might help. First, in the Run/Debug configuration, Make sure the JUnit 4 test runner is selected. Next, if this is a plugin project, add the junit4 runtime to the project as a dependency (in the dependencies tab).