适用于iPhone的样机Web服务 [英] Mockup webservice for iPhone

查看:61
本文介绍了适用于iPhone的样机Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个iPhone应用程序,作为ObjC和Cocoa中编程的简介.我是.net开发人员,因此在Mac上进行编程对我来说是一个全新的世界:)

I want to make an application for iPhone, as an introduction to programming in ObjC and Cocoa. I'm .net developer, so programming on Mac is a whole new world to discover for me :)

我的应用程序将与Web服务通信.我想使用 iCuke 作为测试框架,但我不想每次都连接到该Web服务我运行测试套件的时间.那么,我该如何模拟Web服务响应进行测试?一种解决方案是使用 SoapUI ,但是也许有些解决方案不使用外部工具.

My application will be talking with web service. I want to use iCuke as a testing framework, and I don't want to connect to that webservice every time I ran test suite. So how can I mock a webservice response for testing? One solution could be use of SoapUI, but maybe there is some solution that do not use external tools.

推荐答案

我将为应用程序中对Web服务的调用编写一个包装器.
伪代码中的示例

I would write a wrapper around the calls to the webservice in the application.
Example in Pseudo Code

CallWebService (action, options,...) {
    // Code for connectiong to Webservice
}

然后,您只需模拟该功能,就像您需要任何其他功能一样

Then you just mock of that function just you would like any other function

CallWebService (action, options,...) {
    return true;
}

通过这种方式,您可以模拟Web服务,而不必担心它是Web服务,数据库连接还是其他问题.您可以让它返回true或其他任何值.

This way you can mock of the webservice without bothering about it being a webservice or a database connection or whatever. And you can have it return true or whatever.

祝你好运

更新

要使这一想法更进一步并使您的测试更加强大,可以使用某种测试参数或环境参数来控制模拟的Webservice方法中发生的情况.然后,您可以成功测试代码如何处理来自Web服务的不同响应.
再次使用伪代码:

To take this idea one step further and make your tests even more powerful you could use some kind of test parameters or environment parameters to control what happens in the mocked off webservice method. Then you can successfully test how your codes handels different responses from the web services.
Again in pseudo-code:

CallWebService (action, options,...) {
    if TEST_WEBSERVICE_PARAMETER == CORRUPT_XML
        return "<xml><</xmy>";
    else if TEST_WEBSERVICE_PARAMETER == TIME_OUT
        return wait(5000);
    else if TEST_WEBSERVICE_PARAMETER == EMPTY_XML
        return "";
    else if TEST_WEBSERVICE_PARAMETER == REALLY_LONG_XML_RESPONSE
        return generate_xml_response(1000000);
}

并测试匹配项:

should_raise_error_on_empty_xml_response_from_webservice() {
    TEST_WEBSERVICE_PARAMETER = EMPTY_XML;
    CallWebService(action, option, ...);
    assert_error_was_raised(EMPTY_RESPONSE_FROM_WEBSERVICE);
    assert_written_in_log(EMPTY_RESPONSE_LOG_MESSAGE);
}
...

以此类推,您明白了. 请注意,我所有的示例都是负面测试用例,但这当然也可以用于测试正面测试用例.

And so on, you get the point. Please note that all my examples are Negative test cases but this could of course be used to test Positive test cases also.

这篇关于适用于iPhone的样机Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆