[Cuis-dev] Tests

Luciano Notarfrancesco luchiano at gmail.com
Tue Aug 16 09:49:57 PDT 2022


On Tue, 16 Aug 2022 at 21:56 Hernan Wilkinson <hernan.wilkinson at 10pines.com>
wrote:

> hmm just to clarify, cmd+t is not only for unit tests... it runs the test
> that you are browsing. And cmd+y runs all the tests on the category...
>

Yes, but doesn’t work for tests that require some extra context. For
example, say we have a MatrixTest with an instance variable ‘scalars’ that
tests matrices over a given coefficients ring, and a test method
testDeterminantProduct that creates two random matrices A and B and asserts
that (A*B) determinant = (A determinant * B determinant). I cannot just run
the test with cmd-t or cmd-y without specifying a ring of coefficients. I
came up with two possible ways to implement concrete tests:
1) I make MatrixTest abstract (see TestCase class>>isAbstract) and make
many concrete subclasses that implement #initialize and set ‘scalars’ to
particular rings (for example a MatrixOverIntegersTest that sets scalars to
Z). I’m currently doing this. The drawback of this approach is that I end
up with lots of subclasses that only implement #initialize to set the
scalars.
2) I don’t make subclasses of MatrixTest, and instead build test suits by
instantiating MatrixTest for each coefficients ring I want to test and each
test selector.

Another way to achieve what I need is to copy the test case instead of
>> creating a new one. Just need to implement
>>
>> TestCase>>copy
>>     ^ self class selector: testSelector
>>
>> And in my subclasses I can make sure to copy all the additional state.
>>
>
> That makes sense... and the #debug would do a copy, is that the idea?
>

Yes. I’d prefer if the system didn’t assume it can recreate a test case
from the class and test selector alone. But for now I can continue without
any changes to Cuis, it’s the simplest thing to do, I’ll continue including
those two methods for TestCase in my package.

>

> Also I’d have to implement #isSameAs: in my subclasses
>>
>
> Why?
>

Because two instances of MatrixTest for #testDeterminantProduct but with
different scalars are different, for example one might test the determinant
of matrices over the integers while other tests the determinant over the
rationals (same testSelector, different scalars).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20220816/f027f837/attachment.htm>


More information about the Cuis-dev mailing list