Created
July 2, 2010 14:33
-
-
Save j05h/461435 to your computer and use it in GitHub Desktop.
Test Dependency Task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :test do | |
desc "Ensures there are no dependencies between test classes." | |
task :each => %w(each:functional each:unit each:integration) | |
namespace :each do | |
def each_test(tests) | |
# This is where the magic happens | |
ENV['TESTOPTS'] = '--verbose=progress' unless ENV['TESTOPTS'] | |
tests.each do |path| | |
puts "\n#{path}" | |
ENV['TEST'] = path | |
Rake::Task['test'].execute | |
end | |
end | |
desc "Run functional test classes independently." | |
task :functional do | |
each_test Dir["test/functional/**/*_test.rb"] | |
end | |
desc "Run unit test classes independently." | |
task :unit do | |
each_test Dir["test/unit/**/*_test.rb"] | |
end | |
desc "Run integration test classes independently." | |
task :integration do | |
each_test Dir["test/integration/**/*_test.rb"] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do your test classes depend on one another? Want to be sure they don't? Here's a handy dandy rake task to help.
The idea is to iterate over all test classes and run it in isolation from others. I found in the project I'm working on that some tests had side effects which caused others to fail when run in isolation, but work when running the full suite. It takes a while to run; add it to your CI suite for extra juiciness.
Usage:
rake test:each # Ensures there are no dependencies between test classes.
rake test:each:functional # Run functional test classes independently.
rake test:each:integration # Run integration test classes independently.
rake test:each:unit # Run unit test classes independently.