Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run JUnit automatically when building Eclipse project

I want to run my unit tests automatically when I save my Eclipse project. The project is built automatically whenever I save a file, so I think this should be possible in some way.

How do I do it? Is the only option really to get an ant script and change the project build to use the ant script with targets build and compile?

Update I will try 2 different approaches now:

  1. Running an additional builder for my project that executes the ant target test (I have an ant script anyway)
  2. ct-eclipse, recommended by Thorbjørn
like image 963
cringe Avatar asked Nov 21 '09 13:11

cringe


People also ask

Can JUnit be run automatically?

JUnit provides Test runners for running tests. JUnit tests can be run automatically and they check their own results and provide immediate feedback.

How do I get JUnit to work in Eclipse?

In Eclipse, you create a JUnit test case by selecting in the main window menubar File -> New -> JUnit Test Case. Once you clicked on the item, a big dialog should pop out. In the pop up you can choose the JUnit version (4 is the one we use) and the package and class name of your test case.


1 Answers

For sure it it unwise to run all tests, because we can have for example 20.000 tests whereas our change could affect only, let's say 50 of them, among which are tests for the class we have changed and tests for classes that collaborate with our class.

There is an unseful plugin called infinitetest http://improvingworks.com/products/infinitest/ which runs only some tests ( related to class we've changed ) just after we save changes. It also integrate quite nicely with editor ( using annotations ) and problem view - displaying not-passing tests like errors.

like image 164
Mirek Pluta Avatar answered Nov 10 '22 00:11

Mirek Pluta