February 2018
Intermediate to advanced
406 pages
9h 52m
English
Failure, of course, is always an option, so you need to test for it. I prefer to do failure-path testing in unit tests rather than end-to-end tests. Success requires the entire system to work in concert. A failure response can usually be isolated to one component. That said, it’s often useful to have one end-to-end failure test, especially in cases where the failure is easily causable and visible to a typical user.
I haven’t yet talked about the tools that will allow you to fake failure—that requires a mock object package. (See Chapter 7, Using Test Doubles as Mocks and Stubs.) But in this case it’s not hard to create a real failure by adding a validation that you can then not fulfill.
Let’s first see what an end-to-end ...