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.
我对整个测试场景都很陌生。我一直在阅读有关BDD测试的内容(在我的情况下,我正在编写PHP应用程序,所以我正在研究Behat作为BDD框架),我发现它非常有趣。我在网上搜索了关于api包装器的bdd测试的一些信息,但我发现了很多不同的结果。
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?
我将使用REST api编写一个服务应用程序。但我还需要编写PHP api包装器。所以我的问题是,我应该为包装器编写测试以及我要编写什么样的测试?
1 个解决方案
#1
0
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.
考虑到selenium,你的应用程序使用api之间可能发生的事情以及你的api内部发生的事情,BDD框架可以工作,但它可能会被证明是脆弱的。
There is a great php way of doing this http://docs.guzzlephp.org/en/latest/
有一个伟大的PHP方式这样做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.
如果您喜欢其他语言,可以使用Mule ESB对Web服务API进行测试。我发现它非常擅长针对服务或任何http运行自定义任何东西。如果您喜欢groovy或java Mule ESB非常适合直接在端点上拉出响应,并触发有效和无效请求。它有一个尖锐的点击界面,可用于各种各样的可能性。如果您的api返回xml,您有很多方法可以直接解析它。它也适用于JSON。即使您为数据响应创建了自己的格式,您也可以轻松地深入研究。 Guzzle给你很多相同的但是以一种php curl友好的方式,但没有尖尖的clicky东西。
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.
如果您用于REST API的语言和框架有一个不错的单元测试包,那么特别是在有意义的地方也这样做。我知道你使用的是php而且我讨厌在php中进行单元测试,但有时候当你想要保护某些方法时,你不能以任何其他方式来验证某些方法是否正确。
I have seen successful api test suites created using a javascript testing framework like Jasmine or qUnit as well.
我见过使用像Jasmine或qUnit这样的javascript测试框架创建的成功的api测试套件。
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.
这一切都取决于你对你的api感到满意和你的api的性质以及你认为api的哪些特性很重要。
#1
0
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.
考虑到selenium,你的应用程序使用api之间可能发生的事情以及你的api内部发生的事情,BDD框架可以工作,但它可能会被证明是脆弱的。
There is a great php way of doing this http://docs.guzzlephp.org/en/latest/
有一个伟大的PHP方式这样做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.
如果您喜欢其他语言,可以使用Mule ESB对Web服务API进行测试。我发现它非常擅长针对服务或任何http运行自定义任何东西。如果您喜欢groovy或java Mule ESB非常适合直接在端点上拉出响应,并触发有效和无效请求。它有一个尖锐的点击界面,可用于各种各样的可能性。如果您的api返回xml,您有很多方法可以直接解析它。它也适用于JSON。即使您为数据响应创建了自己的格式,您也可以轻松地深入研究。 Guzzle给你很多相同的但是以一种php curl友好的方式,但没有尖尖的clicky东西。
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.
如果您用于REST API的语言和框架有一个不错的单元测试包,那么特别是在有意义的地方也这样做。我知道你使用的是php而且我讨厌在php中进行单元测试,但有时候当你想要保护某些方法时,你不能以任何其他方式来验证某些方法是否正确。
I have seen successful api test suites created using a javascript testing framework like Jasmine or qUnit as well.
我见过使用像Jasmine或qUnit这样的javascript测试框架创建的成功的api测试套件。
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.
这一切都取决于你对你的api感到满意和你的api的性质以及你认为api的哪些特性很重要。