Lecture 5-Test for inheritance and testing patterns Flashcards
What are 2 examples of inheritance-related bugs?
1.Missing override
2.Direct access to superclass fields from the subclass code
What is the objective of testing inheritance?
Inherited methods should be retested in the context of a subclass.
ex: if we change method m in superclass, we need to retest m inside all subclasses that inherit it.
What is the Liskov Substituion principle (LSP)?
Functions that use references to base classes must be able to use objects of derived classes without knowing it.
What are the effects of inheritance on testing (2)?
1.It does not reduce the volume of test cases.
2.Number of interactions to be verified goes up at each level of the hierarchy.
Why do we test abstract classes?
For functional compliance
What is functional compliance?
It’s a module compliance with some documented or published functional specification.
Functional vs syntactic compliance
For syntactic :
-The compiler can easily test that a class is syntactically compliant to an interface–> all methods in interface must be implemented with the correct signature.
Its tougher for functional compliance…
What does the abstract test pattern provide(2)?
-A way to build a test that can be reused across descendants.
-A test suite that can be reused for future for unidentified descendants ( useful for APIs)
What is the first rule of abstract test?
Write an abstract test class for every instance and abstract class.
*should have test cases that cannot be overriden + an abstract factory method for creating instances of the class to be tested.
What is the second rule of abstract test?
Write a concrete test class for every implementation of the interface
*should extend the abstract test class and implement the factory method.
Let’s make it simple: How do I know if abstract or concrete?
Test defining the functionality of the interface–> ABSTRACT
Test specific to an implementation –>CONCRETE
Why do we use a crash test dummy?
It can be hard to create a situation that will cause the error–> so we fake it!
What are 2 examples of test smells?
1.Eager test
2.Lazy test
When do we use an eager test?
When a test method checks several methods of the object to be tested and becomes hard to read and understand.
What does the eager test do?
Separates the test code into test methods that test only one method, using a meaningful name highlighting the purpose of the test.