I created a cooperation of 4 classes (Python).
class A:
## A, B, C are nested classes of A
class B:
...
class C:
...
class D:
...
## example methods
def newB(self):
return self.B()
def newC(self):
return self.C(self.newB())
I wrote 60 test-methods in 4 test-cases and this was hard work.
Because B, C, D do not offer much behaviour, the A, B, C, D classes shall be subclassed to add new behaviour.
The Problem:
I wrote much test code to ensure that A, B, C, D cooperate right.
If I subclass A, B, C, D to A2, B2, C2, D2 I will need to test the behaviour of A2, B2, C2, D2 in the same way I tested A, B, C, D.
How do I do this?
- subclass all unittests every time I create a new subclass of Database?
- generate the test cases and a suite by a method?
- …
What would be your practices to assure that the subclassed Database works correctly and there is no mistake in it?
Given: unittests, the classes of Database and your subclass(es)
Tests that exist now:
class TestA(unittest.TestCase):
A = A
def setUp(self):
self.a = self.A()
def test_something(self):
...
class MockB(A.B):
...
class AWithMock(A):
B = MockB
class TestAWithMock(TestA):
A = AWithMock
def setUp(self):
self.a = self.A()
def test_something_new(self):
...
class MockB2(A.B):
...
class MockC2(A.C):
...
class MockD2(A.D):
...
class TestWithMock(unittest.TestCase):
def test_b(self):
b = MockB2()
...
def test_c(self):
...
def test_d(self):
...
Now define a subclass A2:
I would subclass your testcase but only override the
setUp/setupmethod as the rest of the API of the subclassA2should be consistent withA.So your test subclass would be just: