1

我正在构建使用 Facebook 服务 JSON API 来获取和更新一个帐户的信息的应用程序。有明确的政策如何将我的个人帐户升级为开发者帐户https://developers.facebook.com/docs/create-developer-account/很清楚(尽管它比以前更糟,例如http:// answers.oreilly.com/topic/483-how-to-create-a-facebook-test-account/)。

问题是 - 如何合法地创建其他 Facebook 帐户来测试 Facebook 事件、友谊等功能的数据交换。我想最好创建测试帐户,用可能保留一段时间的必要信息填充它们,然后在这种预定义的、清晰的环境中进行例如单元测试?

我听说可以有某种临时的 Facebook 测试帐户。我存在这样的帐户,那么这也可能是解决方案 - 即 JUnit 测试套件的设置阶段可以用静态数据填充此类帐户,然后可以执行测试。

测试涉及交换主要用户与其他 Facebook 帐户共享的数据的 Facebook 应用程序的最佳做法是什么。

4

1 回答 1

1

It is probably best for unit testing purposes to not connect to Facebook at all. Instead use a mock object that will return specific JSON data (that your will contain the feature you are testing) and run your tests on that.

This way you don't have to create fake Facebook accounts or worry about network connections being up or down or how many times you run your tests. (I assume facebook has a limit on how many times you can query them per unit of time)

This technique will also allow you to create situations that are either rare or hard to re-create if you were using actual Facebook accounts.

You can later actually test connecting to Facebook as part of integration tests, but you won't need as many tests since the unit tests should cover all your use cases already.

于 2013-08-21T14:40:50.970 回答