3 ms·
Just use mocks for complicated systems
by erhk 5y ago
Just use mocks for complicated systems
- chriswarbo 5y agoNo offense, but I think you've completely missed the point of what my comment was talking about. Mocks are a way to decouple components of a system during tests, e.g. to avoid having tests hammer a real database. I'm talking about the problem of figuring out what to test; in particular, which properties of a system are invariant. For example, lots of unit tests are based on coincidences, for example: { uid = createUser('Alice'); page = renderProfilePage(uid); assert(page.contains('Hello Alice')); } We can turn this into a property test by taking an arbitrary username as an argument: (username: String) => { uid = createUser(username); page = renderProfilePage(uid); assert(page.contains('Hello ' + username)); } However, this test will fail, since this is not an invariant of the system. In particular, it will fail when given an argument like "&<>", since the resulting page will not contain the text 'Hello &<>' (instead, it will contain "Hello &<>"). All sorts of issues like this will crop up as we test more complicated code. For example, certain components might fail gracefully when given certain values (e.g. constructing a '404' return value); that might be perfectly correct behaviour, but it makes useful invariants harder to think of (since they must still hold, even in those cases!) Mocking is completely orthogonal to that. PS: I consider mocking to be a code smell. It can be very useful when trying to improve processes around a legacy system; but things which are designed to use mocking tend to be correlated with bad design.
- mcharezinski 5y agoCommon practise is to write own generators: (username: ArbUsernameValid) => ... ArbUsernameValid covers all relevant Strings that can be used here like take dictionary of names from 100 countries and feed you arb generator
- erhk 5y agoI believe we are not on the same page for wnat we consider a complicated system to be. Do yo assume that $developer it the owner of all code in this mental exercise?