mardi 27 octobre 2015

How to unittest a complex state machine implemented with asynchronous & callback?

A method, Run for example, has several internal state, A, B, C,..., for example.

One possible call chain: User ----> Run --OnSucceed--> A_Handler --OnFail--> E_Handler and so on.

Handlers maybe called in another thread.

Because there are many state transitions in one call to Run and callback handlers may execute in other threads, so the question is:

  1. How to unitest such a method?
  2. Should I check the internal state?
  3. Is there any best practice for asynchronous function unit-testing?

Thanks.

Some related questions:

  1. How to unit test asynchronous APIs?
  2. How to return the response from an asynchronous call?

Aucun commentaire:

Enregistrer un commentaire