Unit testing several implementation of the same trait/interface
Posted
by paradigmatic
on Stack Overflow
See other posts from Stack Overflow
or by paradigmatic
Published on 2010-03-18T09:36:02Z
Indexed on
2010/03/18
11:11 UTC
Read the original article
Hit count: 448
I program mostly in scala and java, using scalatest in scala and junit for unit testing. I would like to apply the very same tests to several implementations of the same interface/trait. The idea is to verify that the interface contract is enforced and to check Liskov substitution principle.
For instance, when testing implementations of lists, tests could include:
- An instance should be empty, if and only if and only if it has zero size.
- After calling clear, the size sould be zero.
- Adding an element in the middle of a list, will increment by one the index of rhs elements.
- etc.
What are the best practices ?
© Stack Overflow or respective owner