Consider the following concrete scenario: Someone has created a lot of tests that fully test the functionality to which a class implementing Collection<E>
must adhere. How is it then possibly to use that test class (in some way) to test concrete implementations of Collection<E>
?
By example:
public class CollectionTest {
//lots of tests here
}
public class ACollection<E> implements Collection<E> {
//implementation and custom methods
}
public class BCollection<E> implements Collection<E> {
//implementation and other custom methods
}
How should I then write the test classes such that least code duplication occurs?
public class ACollectionTest {
//tests for Collection<E>, preferably not duplicated
//tests for custom methods
}
public class BCollectionTest {
//tests for Collection<E>, preferably not duplicated
//tests for other custom methods
}
In other words, is it possible to "extend CollectionTest", but have its tests run on an instance of ACollectionTest
or BCollectionTest
(or more)? Note that the methods are still accessible once you use ACollection<E>
as Collection<E>
for example.