view.onDonateButtonClicked() expect(mock.donate).toHaveBeenCalled() -------------------------------------------------------- Tests the protocol / communication between test subject (view) and its dependencies (delegate)
-------------------------------------------------------- car = Car.create() car.moveTo x: 3, y: 4 expect(car.position).toEqual x: 3, y: 4 -------------------------------------------------------- Use only for testing public attributes (models)
carWindow car.window.close() // asking = wrong car.closeWindow() // telling = right! -------------------------------------------------------- Law of Demeter: Principle of Least Knowledge Know only the surface, not the internals
Complex test -> method does too much? • Many mocks in test -> too many dependencies? • Dependency can't be mocked -> hard coupling! • Testing state of objects -> Split into classes that work together, test this communication instead • Test are not readable -> The method names should express the specific domain clearly!