back to krasimirtsonev.com
to blog's home page

Testing Facebook application

Testing Facebook application

I had a lot of work these days and didn't have time to blog here, but I think that the tips in this article are very useful. The number of Facebook applications is increasing every day. We all know that the testing (debugging) of our code is really important. That's why I decided to share my experience in this area.

You can download the full source code of the examples here.
Check the testing of the JS SDK here http://krasimirtsonev.com/files/testfacebook/js/.
Check the testing of the PHP SDK here http://krasimirtsonev.com/files/testfacebook/php/.

1. Creating facebook application



  • Go to https://developers.facebook.com/apps

  • Click on + Create New App
    Testing Facebook application

  • Type the name of your application and click Continue
    Testing Facebook application

  • Copy/remember your App ID and App Secret
    Testing Facebook application

  • Set your App Domain and Site URL
    (I'm using a virtual host of my local machine. As far as I know currently Facebook doesn't allow the usage of multiple domains.)
    Testing Facebook application

When you have a created application you are ready for testing. Because I have experience only with PHP and JavaScript SDK my examples are related to those areas.

2. Testing with PHP SDK


For my PHP tests I'm using my own version of SimpleTest. Here is a short script that illustrates the usage of Test class.
And the result is:
Testing Facebook application

So, we have a tool for testing. The second thing that we need is the Facebook's PHP SDK. Download it from here and create a new php with the following content:
Firstly we should check if the configuration is available:
After that we have to initialize the SDK and check if there is a token available:
And finally check if there is a logged Facebook user:
The result of this test when I'm logged in is:
Testing Facebook application
Of course the FacebookTestingCase class could be filled with more methods, which may check something else depending on your custom application's logic.

3. Testing with JavaScript SDK


I really like Jasmine for JavaScript testing. That's why I strongly recommend it and I'm using it for this example.
I think that it is a good idea to wrap the Facebook's stuff in a module. You can use this module in some of your next projects and it is much more flexible for testing.
Nothing fancy. Just simple usage of the SDK. Here it is the full Jasmine test:
The result if you are logged:
Testing Facebook application

As a conclusion I could say that the testing of FB applications is not very pleasant task. Facebook still doesn't provide any information if something goes wrong. It will be good if we (as developers) know what exactly is not ok. For example if we use wrong application ID or wrong App Domain name. We should at least receive some result of our requests. I believe that Facebook are going in the right direction.

Download the full source code of the examples above here.
Check the testing of the JS SDK here http://krasimirtsonev.com/files/testfacebook/js/.
Check the testing of the PHP SDK here http://krasimirtsonev.com/files/testfacebook/php/.

Sharing ...
Commenting ...
blog comments powered by Disqus