11

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
Community
  • 1
  • 1
cringe
  • 13,401
  • 15
  • 69
  • 102

6 Answers6

9

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.

Mirek Pluta
  • 7,883
  • 1
  • 32
  • 23
  • Agreed. Inifinitest is the best one I've found, and one of the only ones in active development. – awied Nov 21 '09 at 17:50
  • After thinking about it, I'd like to see a plugin execute the last tests I started manually. That would help a lot right now. Inifitiest looks nice, maybe I try it. But payware is not getting priority... ;-) – cringe Nov 22 '09 at 07:20
4

Right click on your project > Properties > Builders > New, and there add your ant ant builder.

But, in my opinion, it is unwise to run the unit tests on each save.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
3

See if Eclipse has a plugin for Infinitest.

I'd also consider TestNG as an alternative to JUnit. It has a lot of features that might be helpful in partitioning your unit test classes into shorter and longer running groups.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • It does indeed have a plugin that works really well. Tests run quickly and show up as if they ware copiel errors right in the IDE – s3v1 Jun 11 '10 at 15:25
1

I believe you are looking for http://ct-eclipse.tigris.org/

I've experimented with the concept earlier, and my personal conclusion was that in order for this to be useful you need a lot of tests which take time. Personally I save very frequently so this would happen frequently, and I didn't find it to be an advantage. It might be different for you.

Instead we bit the bullet and set up a "build server" which watches our CVS repository and builds projects as they change. If the compilation fails or the tests fail we are notified quickly so we can remedy it.

It is as always a matter of taste what works for you. This is what I've found.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • Ah, sure. Hudson is doing integration, but I find it somewhat annoying to click around in Eclipse just to start the tests after changing. ;-) Maybe the plugin should be so clever to just run the testcases that test the class I changed. Running all tests on every change would be too annoying. – cringe Nov 21 '09 at 17:02
  • Just a question: You do run your unit tests locally before checking in, right? Do you have rule of thumb when you run them? After you think your edit could break something? Or only once before commiting? – cringe Nov 22 '09 at 07:22
  • We do not have full test coverage (ah, the joy of legacy code). I run the tests if I think it's necessary. I _know_ that the build server will run the tests and notify me if they are broken, so I don't _have_ to. – Thorbjørn Ravn Andersen Nov 22 '09 at 08:22
1

I would recommend Inifinitest for the described situation. Infinitest is nowadays a GPL v3 licensed product. Eclipse update site: http://infinitest.github.com

benc_cneb
  • 31
  • 1
-1

Then you must use INFINITEST. INFINITEST helps you to do Continuous Testing. Whenever you make a change, Infinitest runs tests for you.

It selects tests intelligently, and only runs the ones you need. It reports unit test failures like compiler errors, and provides additional information that helps you write better tests.

sachin thakur
  • 91
  • 2
  • 9