You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2012/07/25 15:23:20 UTC

[PATCH core 7/7] Core: Reorganized unit tests and coverage generation

From: Michal Fojtik <mf...@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 <mf...@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


Re: [PATCH core 7/7] Core: Reorganized unit tests and coverage generation

Posted by David Lutterkort <lu...@redhat.com>.
On Thu, 2012-07-26 at 10:45 +0200, Michal Fojtik wrote:
> The problem with VCR is that it needs to points out into different directories
> for different drivers (EC2, RHEV-M). I mean the VCR.configure section.

I was thinking of something as simple as 'vcr_setup(fixtures_dir)' in a
common helper

> Also don't forget that we also want to have tests be able to run separately, mean:
> 
> ruby tests/drivers/ec2/instances_test.rb should work.

Yes, completely agree that that's important - but that just means that
instances_test.rb has to have the right requires up top, rather than
relying on something else being already loaded.

David



Re: [PATCH core 7/7] Core: Reorganized unit tests and coverage generation

Posted by Michal Fojtik <mf...@redhat.com>.
Hi,

On Jul 26, 2012, at 12:47 AM, David Lutterkort wrote:

> On Wed, 2012-07-25 at 15:23 +0200, mfojtik@redhat.com wrote:
>> From: Michal Fojtik <mf...@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
> 
> Why can't we have a common utility method to set up VCR configuration,
> and do the switching in the before method of each test (where you now
> call VCR.insert_cassette) ? Or in $driver/common.rb for all I care, as
> long as it's just a bunch of method calls, rather than actual code.

The problem with VCR is that it needs to points out into different directories
for different drivers (EC2, RHEV-M). I mean the VCR.configure section.

But I see your point and agree that we should move 'common' parts into some
common helper and avoid copying duplicated code.
The other methods (like record_retries or Time class monkey patch) should go
into separate helper file, shared by all tests (like test_helper).

> I actually like having separate tasks for the different drivers, but I
> don't like that e.g. rhevm/common.rb and ec2/common.rb contain a whole
> bunch of code that is duplicated.

Sure, I'll try to move duplicated code into test_helper or some helper in driver
directory (tests/drivers/common.rb).

Also don't forget that we also want to have tests be able to run separately, mean:

ruby tests/drivers/ec2/instances_test.rb should work.

If we will have more 'helpers' then it will be harder to run those files by hand,
because you will need to 'require' them using '-r'.

  -- Michal

---
Michal Fojtik, Sr. Soft. Engineer
Deltacloud API / CloudForms
mfojtik@redhat.com



Re: [PATCH core 7/7] Core: Reorganized unit tests and coverage generation

Posted by David Lutterkort <lu...@redhat.com>.
On Wed, 2012-07-25 at 15:23 +0200, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@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

Why can't we have a common utility method to set up VCR configuration,
and do the switching in the before method of each test (where you now
call VCR.insert_cassette) ? Or in $driver/common.rb for all I care, as
long as it's just a bunch of method calls, rather than actual code.

I actually like having separate tasks for the different drivers, but I
don't like that e.g. rhevm/common.rb and ec2/common.rb contain a whole
bunch of code that is duplicated.

David