Reputation: 501
If I have class A and a subclass B, is there a way to write a test case which will be able to check a function in both classes without code duplication in two separate classes ATest and BTest?
Upvotes: 1
Views: 141
Reputation: 558
You can do the generic tests in TestA using an instance of class A, which is created in the setup
Then extends TestA within TestB and use the instance of class B for the B-specific tests, making sure that you override the setup so this instance is passed to the tests in class TestA
All the unit test cases will be reused without duplication
Upvotes: 1