Avoid coding a tautology • Don’t mock everything! it’s an anti pattern • Don’t mock value objects! • Don’t mock a type you don’t own! • …and a few more. https://github.com/mockito/mockito/wiki/How-to-write-good-tests
= CardPaymentProcessor(transactor) val creditCardNumber = "very-real-much-money" subject.processPayment(creditCardNumber, BigDecimal.TEN) }c Life without mocks
= CardPaymentProcessor(transactor) val creditCardNumber = "very-real-much-money" subject.processPayment(creditCardNumber, BigDecimal.TEN) assertEquals( actual = transactor.getLastPaymentAmount(creditCardNumber), expected = BigDecimal.TEN ) }c Life without mocks
= CardPaymentProcessor(transactor) val creditCardNumber = "very-real-no-money" subject.processPayment(creditCardNumber, BigDecimal.TEN) assertEquals( actual = transactor.getLastPaymentAmount(creditCardNumber), expected = null ) }c Life without mocks
• Martin Fowler “Mocks aren’t stubs” https://martinfowler.com/articles/ mocksArentStubs.html#TheDifferenceBetweenMocksAndStubs • Google ToT “Don’t overuse mocks” https://testing.googleblog.com/2013/05/testing-on-toilet-dont-overuse-mocks.html • Google ToT “Testing state vs testing interaction” https://testing.googleblog.com/2013/03/testing-on-toilet-testing-state-vs.html • Google ToT “Fake your way to better tests” https://testing.googleblog.com/2013/06/testing-on-toilet-fake-your-way- to.htmlhttps://testing.googleblog.com/2013/06/testing-on-toilet-fake-your-way-to.html • r/Androiddev “Do you unit test? If you do, do you use mocking libraries?” https://www.reddit.com/r/androiddev/comments/7l3wrd/android_devs_do_you_unit_test_if_you_do_do_you/ • Jake Wharton “Mockito is a loaded gun” https://twitter.com/jakewharton/status/1103836521327706113 • Eric Smith “Thats not yours” https://8thlight.com/blog/eric-smith/2011/10/27/thats-not-yours.html • Mockito “How to write good tests” https://github.com/mockito/mockito/wiki/How-to-write-good-tests • Uncle Bob “When to mock” https://blog.cleancoder.com/uncle-bob/2014/05/10/WhenToMock.html • Uncle Bob “The Little Mocker” https://blog.cleancoder.com/uncle-bob/2014/05/14/TheLittleMocker.html • Jesse Wilson “Value objects, Service Objects and Glue“ https://publicobject.com/2019/06/10/value-objects-service-objects-and- glue/