3 ms·
> > You don't need the exchange's state to decide what case you are testing > yes you do, thd exchange needs to know the state of the trade. No you really don
by lexicality 3y ago
> > You don't need the exchange's state to decide what case you are testing
> yes you do, thd exchange needs to know the state of the trade.
No you really don't.
For your given example, you configure your application state to think it has just submitted a buy order for 500 units. Then, you write a series of tests that check to see what it does if it receives
- One sell order for 500
- Two sell orders for 250
- Five hundred sell orders for 1
- One sell order for 501
- One sell order for 250 but nothing else for N simulated minutes
- Nothing for N simulated minutes
- The exchange socket closes with an error
- A sell order for -500
- A sell order for NaN
- A buy order for 500
- A corrupted message
- etc etc etc
For unit tests you are not checking the full behaviour of the system, you are checking to see how it behaves in a very specific set of circumstances per test.
If you do not know all the messages this API can reply with then just capture a few days or weeks of traffic and you can make a damn good guess from there.
If your code doesn't support this level of isolation then you need to rewrite it until it can, I highly recommend "Working Effectively with Legacy Code" by Michael C. Feathers to help you.