Unit tests for sub-classes

I posted about this a couple of weeks ago but didn’t get much response
so I
thought I’d try again.

when you create a subclass of Test::Unit::TestCase, e.g. PersonTest (for
model Person), the tests in that class get run automatically whenever
file is loaded. so far so good.

Let’s say I then create a Manager class which subclasses Person. I want
ManagerTest to extend PersonTest. However, because of the automatic
I mentioned previously, if you try to load manager_test.rb, you end up
running both PersonTest and ManagerTest. This may not sound like a big
problem but I have 3 levels of subclasses on about 6 core classes, so
can imagine how long ‘rake test_units’ takes to run!

The only way round it that I’ve found is to create a subclass of
for each model which contains test for the functionality in the parent
and it’s derived class, but that totally violates the DRY principle.
the TestCase for the parent should test the parent functionality, and
subclassed TestCases should test the functionality of the subclasses.

this problem is only going to get worse as I add more parent and
sub-classes, so could someone please save what little hair I have left
suggest a workaround?

thanks for reading

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs