Running Rails Tests in Eclipse Test::Unit GUI

Maybe this is common knowledge, I don’t know. I figured I’d post it,
hopefully it can help some people. If anyone has a better way, please
share.

jrhicks.net (not my blog, I’m Mike in the comments

I couldn’t get it to literally run the test in the identical way as
rails does when you type rake. However, I could get it to run an
individual test file in the GUI, by opening the file and picking Run As
Test::Unit Test off the menu. From there, I figured why fight to do it
the “elegant” way when I can just create a new file that requires all my
test files. There’s no reason one couldn’t get it identical to the “rake
way,” but I didn’t feel like fighting any more.

I made a new file in the test directory, I called it all_tests.rb but
you can call it whatever you want. The contents is (one line):

[“unit”,“functional”].each { |t| Dir.foreach(“test/#{t}”) { |f| require
“test/#{t}/#{f}” if f =~ /.*.rb/} }

There’s no need for it to be a one-liner, I made it that way cause …
well cause of the same reason anyone makes an unnecessary one liner, for
fun. That will call “require” on each one of your test files. If you
have additional directories other than unit and functional with test
files, just add them in the array.

Run that file with Run As/Test::Unit Test and it should run all your
tests in the GUI. I remapped Run As Test::Unit Test to Ctrl-T in my
environment, just for convienence, so it’s open that file/Ctrl-T.
Obviously that’s optional.

It’s not QUITE as convienent as the ideal (a keystroke AND A MOUSE
CLICK?!?!?!?!?!?!?!?!?!) but it’s pretty darn good.

Hey Mike,

thanks for sharing this. I’ve just tried it. Works great!

Regards
Jan P.