The document discusses principles for clean code in test automation. Clean code should be readable, maintainable, and have clear intent through proper naming, following SOLID principles like the single responsibility principle, and refactoring code. This results in test automation code that has increased readability and maintainability and is easier to extend. The document also discusses different types of test doubles like stubs, spies, and mocks that can be used in unit tests.
Clarify what I mean with test abstraction and that we strive towards clean code in the test abstraction layer
What is your first impression?
Naming?
Clarity?
Clean code example does the same thing as the smelly code!
Explain God classes, bloaters (methods) as signs of violating SRP.
Single responsibility states that every class should only have one reason to change.
Explain God classes, bloaters (methods) as signs of violating SRP.
Single responsibility states that every class should only have one reason to change.
Explain God classes, bloaters (methods) as signs of violating SRP.
Single responsibility states that every class should only have one reason to change.
11
Explain God classes, bloaters (methods) as signs of violating SRP.
Single responsibility states that every class should only have one reason to change.
Make sure your inheritance is justified.
Remove inheritance.
Make an abstract class Shape with abstract method getArea();
Implement it in both.
Explain God classes, bloaters (methods) as signs of violating SRP.
Single responsibility states that every class should only have one reason to change.
Explain God classes, bloaters (methods) as signs of violating SRP.
Single responsibility states that every class should only have one reason to change.
Make an interface LoanValidator
20
Dummy objects are passed around, never used. Used to fill parameter lists.
Fake objects have working implementations, take shortcut e.g InMemoryTestDatabase
Stubs provide canned answers to calls made during the test
Spies are stubs that also record some information based e.g an email service that records how many messages it has sent.
Mocks are pre-programmed with expectations which form a specification of the calls they are expected to receive. They can throw an exception if they receive a call they don't expect and are checked during verification to ensure they got all the calls they were expecting.