Is there an easy ruby or rails command to get a list of all the tests in an application? I use Shoulda primarily, but if there's a ruby solutio开发者_StackOverflown regardless of test suite that would work too.
I have found a roundabout solution: the test_benchmarker plugin. You run your tests with an extra environment variable like so:
rake test BENCHMARK_TESTS=true
You're best off piping the output to a file, because it will be long. But it will give you a list of all the test classes and tests themselves, for both unit and functional. Obviously it gives you the benchmarking results too, which is a bonus.
Is there anything better? I guess this is pretty close, and the extra effort is so little, why NOT get the benchmark results too? RSpec has this feature built in, but maybe it'd be fun to write a version for Test::Unit.
I don't think there can be a one-solution-fits-all answer here: how tests are identified is going to be framework-dependent to a great extent. Once you're into frameworks like shoulda, it's near-enough impossible to identify all tests without executing them, consider the case where you have should
requirements within a loop, for example.
Listing all tests as they're executed would be a matter of digging into the framework code for the point where the individual tests are identified/generated and extracting the information needed.
I'd be interested to learn if (and how) I'm wrong, though...
I think you need this. It's what the "rails test" command does
tests = Rake::FileList["test/**/*_test.rb"]
精彩评论