From: Phil Tomson Date: 2002-03-30T06:51:55+09:00 Subject: Re: RUNIT: mixin instead of inheriting? On Fri, 29 Mar 2002, Matt Armstrong wrote: > ptkwt@shell1.aracnet.com (Phil Tomson) writes: > > > I'm wondering if it's possible (or if it could be acheived without > > too much change to RUNIT) to mixin functionality from > > RUNIT::TestCase into a class instead of inheriting: > > > > Currently we have to do: > > > > class TestingMyDesign < RUNIT::TestCase > > .... > > def test_MyDesign > > ... > > end > > end > > > > I would like to be able to do: > > > > class MyDesign < Design #I have a class to inherit from already > > include RUNIT::TestCase > > .... > > def test_MyDesign > > ... > > end > > end > > > > md = MyDesign.new() > > .... > > > > md.run_suite > > > > Would it make sense? > > It might even work, but then the class you're testing would actually > be a test class. Unit tests are supposed to use the objects they are > testing in a similar way a programmer would. Actually making the > class being tested a unit test seems odd. What is your motivation for > wanting to do this? > Yes, it's rather odd. Let me try to explain: I'm making this module that allows one to describe & simulate hardware in Ruby (RHDL). Now, in mainstream Hardware Description Languages(HDL) the designer will design the hardware model and then make something called a Testbench which is also written in the HDL. The Testbench is used to determine if the model of the hardware being described is functionally correct. This is in some sense similar to the concept of Unit testing in the software world. In a testbench you test the value of certain signals at certain times and if they don't match what you expect you can assert an error. So my idea was that if Test::Unit was mixed in, the design would contain the testbench as well. Perhaps it doesn't make much sense, though. I can certainly live with the current way of doing it, but the potential advantage of the other is that I could put asserts within the actual design itself and have their pass/fail status be tracked as well. Phil