In larger projects, there can often be a group of tests that test the functionality of related classes. These tests often share a lot of setup and preparation functionality.
What happens then is that a base class is defined for these test cases so that they can share there instance fields and common functionality. This leads to problems when a test uses a lot of functionality present in multiple classes.
Would it be possible to use some form of composition for this type of code reuse?
Let me give a concrete example. I have a few classes that can 'write' a list of transactions, defined by the interface 'TransactionWriter'. Concrete implementations are 'FileTransactionWriter' and 'ConsoleTransactionWriter'.
Both of the test classes for these implementations would need to set up transactions with some arbitrary data. This code would be duplicated in both classes if not extracted to a base test class. But can the same goal be achieved with composition?