deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 7/7] Core: Reorganized unit tests and coverage generation
Date Wed, 25 Jul 2012 13:23:20 GMT
From: Michal Fojtik <mfojtik@redhat.com>

Since each driver test use it's own VCR settings, it is not
longer possible to load all tests at once with rake test.

For this this patch will split different test tasks so drivers
do no overide their VCR configurations

Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/.simplecov           |   11 ++++++++
 server/Rakefile             |   65 ++++++++++++++++++++++++++++++++++---------
 server/tests/test_helper.rb |   13 ---------
 3 files changed, 63 insertions(+), 26 deletions(-)
 create mode 100644 server/.simplecov

diff --git a/server/.simplecov b/server/.simplecov
new file mode 100644
index 0000000..5feea29
--- /dev/null
+++ b/server/.simplecov
@@ -0,0 +1,11 @@
+SimpleCov.start do
+  command_name 'Minitest tests'
+  project_name 'Deltacloud API'
+  add_filter "tests/"
+  add_group 'Drivers', 'lib/deltacloud/drivers'
+  add_group 'Collections', 'lib/deltacloud/collections'
+  add_group 'Models', 'lib/deltacloud/models'
+  add_group 'Helpers', 'lib/deltacloud/helpers'
+  add_group 'Extensions', 'lib/deltacloud/core_ext'
+  add_group 'Sinatra', 'lib/sinatra'
+end
diff --git a/server/Rakefile b/server/Rakefile
index 41eb7fa..c42ea4b 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -108,18 +108,57 @@ task :routes do
   end
 end
 
-Rake::TestTask.new do |t|
-  t.ruby_opts << '-r./tests/test_helper.rb'   # Load SimpleCov when COVERAGE=1 is set
-  unless RUBY_VERSION < '1.9.0'
-    t.loader = :testrb
+DRIVERS = [:mock, :ec2, :rhevm]
+
+desc 'Run all tests'
+task :test do
+
+  Rake::Task["mock:fixtures:reset"].invoke
+  puts "\n[ \033[1;37;mrake test:base\33[0m ]\n"
+  Rake::Task["test:base"].invoke
+  DRIVERS.each do |driver|
+    puts "\n[ \033[1;37;mrake drivers:#{driver}\33[0m ]\n"
+    Rake::Task["test:drivers:#{driver}"].invoke
   end
-  t.test_files = FileList[
-    'tests/helpers/**/*test.rb',              # Deltacloud extensions (core_ext) and other
helpers
-    'tests/drivers/base/*test.rb',            # Deltacloud drivers API tests
-    'tests/drivers/models/*test.rb',          # Deltacloud models tests
-    'tests/deltacloud/*test.rb',              # Deltacloud internal API tests
-    'tests/deltacloud/collections/*test.rb',  # Deltacloud collections
-    'tests/drivers/mock/*test.rb',            # Deltacloud Mock driver specific unit tests
-    'tests/drivers/ec2/*test.rb'              # Deltacloud EC2 driver specific unit tests
-  ]
 end
+
+namespace :test do
+
+  desc "Run all tests and generate code coverage report"
+  task :coverage do
+    ENV['COVERAGE'] = '1'
+    puts "[ \033[1;37;mCoverage report will be generated to server/coverage\33[0m ]\n\n"
+    Rake::Task["test"].invoke
+  end
+
+  namespace :drivers do
+
+    DRIVERS.each do |driver|
+      Rake::TestTask.new(driver) do |t|
+        t.ruby_opts << '-r./tests/test_helper.rb'   # Load SimpleCov when COVERAGE=1
is set
+        unless RUBY_VERSION < '1.9.0'
+          t.loader = :testrb
+        end
+        t.test_files = FileList["tests/drivers/#{driver}/*test.rb"]
+      end
+    end
+
+  end
+
+  Rake::TestTask.new(:base) do |t|
+    t.ruby_opts << '-r./tests/test_helper.rb'   # Load SimpleCov when COVERAGE=1 is
set
+    unless RUBY_VERSION < '1.9.0'
+      t.loader = :testrb
+    end
+    t.test_files = FileList[
+      'tests/helpers/core_ext/*test.rb',        # Deltacloud extensions (core_ext) and other
helpers
+      'tests/drivers/base/*test.rb',            # Deltacloud drivers API tests
+      'tests/drivers/models/*test.rb',          # Deltacloud models tests
+      'tests/deltacloud/*test.rb',              # Deltacloud internal API tests
+      'tests/deltacloud/collections/*test.rb',  # Deltacloud collections
+    ]
+  end
+
+end
+
+
diff --git a/server/tests/test_helper.rb b/server/tests/test_helper.rb
index 5aed571..0b40610 100644
--- a/server/tests/test_helper.rb
+++ b/server/tests/test_helper.rb
@@ -2,22 +2,9 @@ require 'pp'
 
 ENV['RACK_ENV'] = 'test'
 
-%x[rake mock:fixtures:reset]
-
 if ENV['COVERAGE']
   begin
     require 'simplecov'
-    SimpleCov.start do
-      command_name 'Minitest tests'
-      project_name 'Deltacloud API'
-      add_filter "tests/"
-      add_group 'Drivers', 'lib/deltacloud/drivers'
-      add_group 'Collections', 'lib/deltacloud/collections'
-      add_group 'Models', 'lib/deltacloud/models'
-      add_group 'Helpers', 'lib/deltacloud/helpers'
-      add_group 'Extensions', 'lib/deltacloud/core_ext'
-      add_group 'Sinatra', 'lib/sinatra'
-    end
   rescue LoadError
     warn "To generate code coverage you need to install 'simplecov' (gem install simplecov
OR bundle)"
   end
-- 
1.7.10.2


Mime
View raw message