11

With Ruby on Rails, I could use autotest, to run all my tests automatically each time, when I saved a file of my code. Additionally, the framework started only the tests that were affected by the change and it notified me of the test results. Is there anything similar for my java development when using Eclipse?

I don't want something that generates tests for me, it just should start the right tests at the right time automatically.

grackkle
  • 776
  • 1
  • 9
  • 26

4 Answers4

5

Possibly Infinitest could interest you.

Omnaest
  • 3,096
  • 1
  • 19
  • 18
  • That sounds quite interesting and half of the answer to my question. If I understand it right, it does run all tests, that match a specific regex each time, when I save a file. I still leaves the part of choosing the right tests automatically open... And I didn't find a good documentation other than the webpage that you posted. – grackkle Jun 23 '11 at 04:36
  • @bln-tom They obviously moved their project since a while. In [this](http://stackoverflow.com/questions/4842042/is-it-possible-to-run-incremental-automated-junit-testing-in-eclipse) task there are some more plugins mentioned. – Omnaest Jun 23 '11 at 07:12
  • If I'm not mistaken, it's not tests that match a regex. It's all tests that call code that you've changed since your last save. In other words, it will automatically figure out which tests need to be rerun and which ones don't. I'm sure it's not perfect (if you use reflection I imagine that could cause some problems) but since Eclipse can already identify call hierarchies and such, I would guess it's pretty damn good. Though I haven't used it too much myself, to be honest. – Tyler Jun 26 '11 at 23:40
2

If you've got a maven-ish directory layout, you could use SBT (https://github.com/harrah/xsbt/) and run ~test in a terminal in the background. It doesn't (as far as I know) have autotest's ability to inteligently run a subset of tests, but other than that it's very similar in operation.

Chris May
  • 670
  • 3
  • 6
0

If you were using Maven, you could do this by changing the goals in Project -> Properties -> Maven -> Lifecycle Mappings.

You could probably do something similar with an Ant Builder.

However I don't think that the builders are able to figure out that a specific test needs to be run. Running all tests on each file save is liable to make Eclipse sluggish.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • I use Maven, so that's not the point, but still I have to run the build command manually. What is needed are two mechanisms: 1) some kind of event that triggers testing on file save 2) a choice of relevant tests (probably by naming conventions?) I think, it wouldn't be a problem to have the test running so often, if you choose only the few relevant and if you write tests as one should write them: As a list of border-cases and not test cases that run for minutes. – grackkle Jun 13 '11 at 15:20
0

What I did in my Software Engineering class was to enable Eclipse to save automatically before each run. Then I had an ANT build Script which compiled and ran all the JUnit tests we had. It also generated the updated JavaDocs and JAR'd the whole program for us.

Here is the ANT main page and here is a nice tutorial to get you started.

Peaches491
  • 1,239
  • 15
  • 27
  • what you describe is what maven does for you. you just don't have to write ant scripts anymore with maven. it still doesn't allow to run the right tests after each file-save – grackkle Jun 13 '11 at 21:21
  • Well, typically on a large project, the test set will contain dozens, if not hundreds of tests. These can take several minutes to complete. I can't imagine running all the tests we had generated after each file save. However, we did have a Continuious Integration program called [Hudson](http://hudson-ci.org/) running alongside our SVN. It built and tested the code after each `commit` It also emailed the team if there were any errors and informed us of who made the commit. It certainly saved our butts on more than one occasion – Peaches491 Jun 14 '11 at 12:54
  • that why I don't want to run all, but the nessecary tests to run. I'd call it the local test layer, which tells the programmer, that the stuff, he's actually working on is broken or not. What you describe would be the second layer, which tests after a commit (and then all tests). As I said, with ruby on rails there was such a testing package, and it was a pleasure to work with it. You simply know that you'll get a message whenever you have broken something, and otherwise is runs silently in background. – grackkle Jun 14 '11 at 13:03
  • That sounds very convenient, indeed. Unfortunately I am unaware if such a plugin exists. Best of luck though! Be sure to answer your own question if you find a suitable match! – Peaches491 Jun 14 '11 at 13:31