dousuo2812 2012-12-15 13:11
浏览 6

我应该为rest api包装器编写测试吗?

I'm very new to the whole testing scene. I've been reading about BDD testing (in my case I'm writing PHP applications, so I was researching Behat as a BDD framework) and I find it very interesting. I've searched online for some information on bdd testing for api wrappers, but I found a lot of different results.

I'm going to write an application for a service with a REST api. But I also need to write the PHP api wrapper. So my question is, should I be writing tests for the wrapper and what kind of tests shoud I be writing?

  • 写回答

1条回答 默认 最新

  • douzhuiqiu4923 2013-01-08 05:52
    关注

    A BDD framework could work but it might prove to be fragile considering the possibilities of what might happen between selenium, your app using the api, and whats going on inside your api.

    There is a great php way of doing this http://docs.guzzlephp.org/en/latest/

    If you like other languages you could use Mule ESB to do testing against web service api. I have found it to be very good at running custom anything against a service or anything http. If you like groovy or java Mule ESB is perfect for getting directly at an endpoint to pull the reponse apart and fire off valid and invalid requests. It has a pointy clicky interface for a large variety of possibilities. If your api returns xml you have plenty of ways to parse it directly. It works well with JSON too. Even if you created your own format for the data response you can just dig into that fairly easily. Guzzle gives you much of the same but in a php curl friendly way but no pointy clicky stuff.

    If your language and framework you are using for your REST api has a decent unit testing package then do that too especially where it makes sense. I know you are using php and I hate unit testing in php but sometimes you can't do it any other way to verify certain methods are correct when you want to protect certain methods.

    I have seen successful api test suites created using a javascript testing framework like Jasmine or qUnit as well.

    It all depends on what you are comfortable with and nature of what is going on with your api and what features of your api you would consider are important to cover.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考