This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 158171 - not all tests are run when 'inherited()' is used in test class
Summary: not all tests are run when 'inherited()' is used in test class
Status: NEW
Alias: None
Product: ruby
Classification: Unclassified
Component: Testing (show other bugs)
Version: 6.x
Hardware: All Linux
: P4 blocker (vote)
Assignee: issues@ruby
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-09 02:21 UTC by bgoodspeed
Modified: 2011-01-28 20:13 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
test case to demonstrate focused unit test problem (438 bytes, text/plain)
2009-02-09 02:23 UTC, bgoodspeed
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bgoodspeed 2009-02-09 02:21:40 UTC
CONTEXT:
Given a base test class, which uses the ruby method "inherited(subclass)" to define additional test methods on
subclasses, when these subclasses are tested through the NB ruby gui "test file" tool, they will not have all defined
tests run.

I have 2 test methods defined in the two classes: (actual test case will be attached)
base_class: test_shutup_runit (this test only exists to silence rUnit complaints about a subclass of TestCase with no
test methods)
subclass: test_meta_programming*

where * denotes the test method created by "class_eval" in the "inherited(subclass)" method mentioned above.

ISSUES:
(1) test_meta_programming() does not run, only test_shutup_runit runs.
(2) the initialize(suite) method for the subclass does not execute.

These two issues do not present themselves when the same test is run on the command line or through rake.

My Guess:
Perhaps the test case is created using reflection without calling "new()" or "initialize(test_suite)"?
Comment 1 bgoodspeed 2009-02-09 02:23:49 UTC
Created attachment 76722 [details]
test case to demonstrate focused unit test problem
Comment 2 bgoodspeed 2009-02-09 02:25:32 UTC
This bug is triggered when you right click the test and invoke "test file" or "run file"
Comment 3 Erno Mononen 2009-02-09 08:03:28 UTC
Thanks for the report, reproduced with the file you attached. I'll have a look at this.
Comment 4 Erno Mononen 2009-02-09 09:13:46 UTC
I'm not sure yet how to fix this in NB, but as a workaround you can get your tests working by implementing the 
inherited method in your test case as follows:

  class << self
    alias_method :org_inherited, :inherited
    def inherited(sub)
      org_inherited(sub)
      sub.class_eval do
        define_method :test_meta_programming do
          assert_equal "meta", "not meta :("
        end
      end
    end
  end

The problem with the way it's done in the example you attached is that it doesn't delegate to previous implementations, 
which causes problems since the NB test runner also needs to implement this method. I'll see if I can somehow come up 
with another solution, but as long as we need to implement inherited in the test runner it might be a bit challenging.
Comment 5 Erno Mononen 2010-05-06 11:43:34 UTC
I suppose this issue doesn't affect that many users, and there is a workaround for this, so I'm adjusting the priority for now - let's increase it again if more folks run into this. Also, I haven't been thinking about this too much lately, but I still can't come up with with a way to fix the NB test runner to avoid the issue.