how would I test microservices?

Well. Imagine that I would have simple microservice that is small Express application that serves data from DB and transforms it.

First I would think about proper design of code.

I would split code into:

  • initialization part (creating Express app) - smoke tests would be sufficient
  • Express endpoints - they will be set appropriate headers and integrate logic and DB. I would tests more overally - if headers are correct etc.
  • logic - this is meat, so I would test more thorougly this. Logic would be probably in pure functions. Easy to test. (that's one of reasons I don't want to put to much logic in endpoints themselves because they are harder to test).
  • wrapper for DB - I would test e2e with some kind of development database in play.

Maybe I would also make some kind of automatically generated tests for endpoints. I mean. I would already test logic so no need to duplicate code, but to ensure that endpoint really returns logic.

I would probably make functions like testSomeLogic() and use these functions in both unit tests for logic and in tests for endpoints. Maybe I would create some kind of array of these functions to automatically apply them.

I would also want to have some kind of integration/e2e tests between various microservices in cluster. Not between all, but e.g. to check interactions between 3-5 microservices at once. So I would set some cluster, databases etc.

Comments

Popular posts from this blog

First steps with Plotly.js

How to be a modern front-end dev?