单元测试Silverlight-Facebook应用程序的服务器接口 [英] Unit Testing the Server Interface for a Silverlight-Facebook Application

查看:162
本文介绍了单元测试Silverlight-Facebook应用程序的服务器接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Silverlight 4客户端在Google App Engine上托管的Facebook页面上运行。它正在使用 gminifb 与Facebook API通信。 Silverlight客户端使用每个方法的URI进行POST调用,并在每次调用时从Facebook传递会话信息。

I have a Silverlight 4 client running on a Facebook page hosted on Google App Engine. It's using gminifb to communicate with the Facebook API. The Silverlight client uses POST calls to the URIs for each method and passes the session information from Facebook with each call.

项目的增长,如果我可以设置一个单元测试系统来进行各种服务器调用,以便在进行更改时,我可以确保其他所有操作都可以正常工作。之前我已经使用过 nUnit ,我喜欢我读过的 PEX ,但我不知道如何将它们应用于这种情况。

The project's growing and it would be super-useful if I could set up a unit-testing system to make a variety of the server calls so that when I make changes I can ensure everything else still works. I've worked with nUnit before and I like what I've read of PEX but I'm not sure how to apply them to this situation.


  1. 为此创建测试系统有什么选择?每个的优点/缺点?

  1. What're the choices for creating a test system for this? Pros/cons of each?

如何开始设置这样的东西?

How do I get started setting something like this up?


推荐答案

已解决。我做了如下:


  1. 创建了一个特殊的用户帐户,用于绕过身份验证的服务器进行测试。只有在测试环境中,才能在该环境的设置中检查一个调试标志。这样可以避免在实时站点中创建任何安全漏洞(因为相同的调试标志会在那里出错)。

  1. Created a special user account to be used for testing on the server that bypassed the authentication. Only did this on the test environment by checking a debug flag in that environment's settings. This avoided creating any security hole in the live site (since the same debug flag will be false there.)

创建了一个C#.NET解决方案来测试每个API呼叫。主机项目是三个可重用的同步方法的控制台应用程序(不需要GUI):

SendFormRequest(WebRequest请求,字典< string,string>对)

GetJsonFromResponse(HttpWebResponse响应)

ResetAccount()

这三个方法允许主机项目在服务器上发出HTTP请求并读取JSON响应。

Created a C#.NET solution to test each API call. The host project is a console app (no need for a GUI) with three reusable synchronous methods:
SendFormRequest(WebRequest request, Dictionary<string,string> pairs),
GetJsonFromResponse(HttpWebResponse response),
and ResetAccount().
These three methods allow the host project to make HTTP requests on the server and to read the JSON responses.

在主机项目的方法调用中包裹每个服务器API调用。

Wrapped each server API call inside a method call in the host project.

创建了一个 nUnit 测试项目中的解决方案。然后简单地创建在主机项目中调用每个包装方法的测试,使用不同的参数,并在服务器上更改值。

Created an nUnit test project in the solution. Then simply created tests that call each wrapper method in the host project, using different parameters and changing values on the server.

创建了一系列测试来验证是否正确无效参数和数据的错误处理。

Created a series of tests to verify correct error handling for invalid parameters and data.

它工作正常,已经确定了一些已经发现的小问题。结果非常有用,并将检查新部署的突破性变化。

It's working perfectly and has already identified a few minor issues that have been found. The result is immensely useful and will check for breaking changes on new deployments.

这篇关于单元测试Silverlight-Facebook应用程序的服务器接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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