Clean & Quality unit tests
May 10, 2015
Clean & Quality unit tests
Wojtek Zieliński
@codecleaner
• Names matters
• Exceptions
• Test Doubles
• Stubbing Collections
• Arrange Act Assert
What’s it all about?
Names matters
Test a single concept in each test function
Robert C. Martin
Exceptions
Test Doubles
How does getMock() really work?
• Does Configuration class exist?
• Create Mock_Configuration_123abc class extends Configuration class
• Create instance of that class
• Return instance
How does getMock() really work?
• Does Configuration class exist?
• Create Mock_Configuration_123abc class extends Configuration class
• Create instance of that class
• Return instance
• Create Configuration class
Stubs provide canned answers to calls made during the test
"Mocks Aren’t Stubs" Martin Fowler
Mocks are objects pre-programmed with expectations which form a specification of the calls they are expected to receive
"Mocks Aren’t Stubs" Martin Fowler
Stubbing collections
Arrange Act
Assert
It’s all about readability
What’s next?
Questions?
Wojtek Zieliński
@codecleaner