As you probably know, every time you run the tests, the whole rails
environment is loaded, which alone takes about 20 seconds on a empty
rails project for me.
I was thinking of running some kind of test server (using DRb) in the
background that loads the environment once, and then just communicates
with the rake task. It would basically reload the testcase files, run
them and and output the results back to the rake task. No reload
environment on every test run.
Even webserver could be used, so we could have built-in controller at
/test that would allow developers to run the tests in browser!
Any ideas or thought why this shouldn't be posssible or why it isn't
already done?
Exactly what has been on my mind lately. Maybe it’s already done? The problem remains - what will run the process, how will we communicate with it, will it be portable (think Windows/Linux/OS X differences)?
Looks great to me. It requires firing up a browser, but don’t we work in browsers anyway? Of course, the possibility to test from the vanilla console always remains (for automation).
If you use RSpec, it has an rspec_rails runner that uses DRb to run load the environment one in the background.
I've not played around with it so I'm not certain how stable it is - but even if you aren't using RSpec it might be worth taking a look around the source as a starting point for something similar for Test::Unit (although I'd be surprised if something isn't already out there).
As you probably know, every time you run the tests, the whole rails
environment is loaded, which alone takes about 20 seconds on a empty
rails project for me.
I was thinking of running some kind of test server (using DRb) in the
background that loads the environment once, and then just communicates
with the rake task. It would basically reload the testcase files, run
them and and output the results back to the rake task. No reload
environment on every test run.
Even webserver could be used, so we could have built-in controller at
/test that would allow developers to run the tests in browser!
Any ideas or thought why this shouldn't be posssible or why it isn't
already done?
This interview with Ryan Davis, at InfoQ, suggests that ZenTest [1] will get this capability:
"Q: And you don't have the cost of starting the Ruby executable in the Rails environment every time you want to run a test?
we didn't want to have ourselves accidentally infect our results and so we're shelling out and invoking the right test files, sometimes with -n in order to name what particular test case we want, but we're still invoking that, we still get that cost. But we're working on tools to address that as well. We're building a tool that will actually be hooked-in automatically from autotest that will load up config/environment.rb, which is the bootstrap mechanism for Rails and incurs the most costs for loading much of anything. It will load all that stuff up, get everything initialized, set up the paths and everything and then open up a socket with an interface to interact with it, saying "I want you to run this class test with this test method and it will fork so that you've copied your cost of initializing and run just those things so you don't have that cost anymore. Basically we've seen a 10x improvement in speed."