RhubarbPHP / Module.RestApi

A module to provide classes for building ReSTful APIs
Apache License 2.0
0 stars 0 forks source link

Best methods to Unit test Rest API endpoints #24

Open miscampbell opened 5 years ago

miscampbell commented 5 years ago

Hi guys

One we could discuss at some stage am wondering what the best way forward is to Unit test a Rest API endpoints? Would like to have this discussion now as we setup v3 of the module so we can bake any changes in from the start.

samnotsowise commented 5 years ago

I usually just do integration tests with request objects built in code with each accepted parameter and assert response content/codes. I tend towards integration testing for apis cause testing the routing and handling layers together is what you're really after - I find with apis there's a lot of redundant work in unit testing handlers and routers. if you're writing complex code in your api worthy of unit testing IMO you're probably doing it wrong, it should just be an interface for your application.