3 ms·
What do you mean by simulators? An anonymized copy of a database or something similar?
by collyw 5y ago
What do you mean by simulators? An anonymized copy of a database or something similar?
- mirekrusin 5y agoIt means external services your project depends on in production should: 1. be used directly if possible/practical, if not... 2. ...then it's likely better to write simulators for them as opposed to mocking individual methods on the client in individual tests There are several factors to consider. External services need to be able to run in isolated, temporary environments with short bootstrap time – if that's not possible, it's better to write simulator which provides this functionality. Services must provide determinism, if they don't, simulator should probably be written with control apis to provide this functionality etc. In general the idea can be summarized as opting for using the highest level of functionality available so tests capture as wide code surface (used in production) as possible. It complements, not replaces, lower level methods – ie. it still makes perfect sense to structure code as composition of pure functions with unit tests. It still makes sense to rely on static analysis and do not test in unit tests what is guaranteed by static type system etc. The side effect of simulators means you can bootstrap your project locally in lightweight fashion for development - with all simulated functionality available. For example if you're working on trading application, instead of mocking at the low level prices, order creation calls etc. it's better to write exchange simulator and use it instead – where full lifecycle of an order will work as expected – in tests and locally, when developing application.