Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perl test suite for API

I'm writing a perl module that interfaces with an API and I would like to write a test suite for it before putting it up on CPAN. However, because this module is basically just an interface for an API, all tests would require a valid API key and user. Obviously I can't release this module with my API key and username in the test suite, so what is the best way to handle something like this? Should I just test locally and then put it up on CPAN with no tests? Has anyone run into this before and come up with a good solution? I know that writing tests is best practice, so I'd like to do it if I can. Thanks!

like image 798
srchulo Avatar asked Jul 09 '13 21:07

srchulo


2 Answers

Why not wrap the API calls into small functions (e.g. the function does NOTHING but the API call), and then mock those functions in your tests as needed using Test::MockObject or similar?

This would be even better, as you would be able to have tests that test different results from API (failure, auth failure, etc...)

like image 127
DVK Avatar answered Sep 22 '22 23:09

DVK


I made it clear in my documentation that my module was useless without an API key, and used skip:{} constructs of Test::More to skip all the tests if the key was not present. You can choose too bail_out instead of skip.

Just insure that your docs explain how to communicate the API key to the module.

like image 26
Len Jaffe Avatar answered Sep 23 '22 23:09

Len Jaffe