Java API for testing Facebook application integration

Since november 2010 you may create test user accounts on Facebook for your application, so that you may test your application without creating dummy accounts and possibly break the Facebook EULA. The test users may be managed using the Facebook Graph API.

The application I was working on, which integrated with Facebook, needed automated integration tests but I could not find any Java API for managing test users. The end result is facebook-test-java-api, a project aimed at testing Facebook application integration.


FacebookTestUserStore facebookStore = new HttpClientFacebookTestUserStore("<appId>", "<appSecret>"));
FacebookTestUserAccount account = facebookStore.createTestUser(true, "");

Where <appId> and <appSecret> should be replaced with the values from your application.

From the FacebookTestUserAccount, you have access to the different user objects, such as the wall, friends, events etc.

String friendsAsJsonString = account.getFriends();

Assertions may be made on the JSON strings using your favorite toolkit, such as json-path (Yes Kalle, I’m looking at you. Time to release it!)

You can also let two test users be friends by issuing:

FacebookTestUserStore facebookStore = new HttpClientFacebookTestUserStore("<appId>", "<appSecret>"));

FacebookTestUserAccount account1 = facebookStore.createTestUser(true, "read-stream");
FacebookTestUserAccount account2 = facebookStore.createTestUser(true, "read-stream");


When creating automated tests you probably want to start with a known state for your application. Use the void deleteAllTestUsers() method on the user store to start with an empty set of users. You can also get a list of available test users from the store by calling the getAllTestUsers() method.

List<FacebookTestUserAccount> users = facebookStore.getAllTestUsers();


For automated tests integrating with Facebook, the application need the access token for the test user to perform operations on its behalf. Here is an example of how a test case could look like.

FacebookTestUserAccount account = facebookStore.createTestUser(true, "email,read-stream");

systemUnderTest.doStuffIntegratingWithFacebook( account.accessToken() );

assertTrue("Wall did not contain expected data", account.getProfileFeed().contains("stuff posted on wall"));

How to get it

It is available on Maven central, use the following dependency:


or have a look at the project page for downloads:

This Post Has 15 Comments

  1. Feroz


    This is really great, thank you, but have a question.
    I’ve used your API and it works fine, but i couldnt find anything like :” Adding existing test users to other apps”, is this possible through this API?

    1. Kyle

      Its not search enenigs that execute the javascript. Its your browser that redirects you to another page when it reads the javascript in your page. Search enenigs simply ignore the code that is included in javascript. Javascript runs on your machine through your browser and not by search enenigs.

  2. Hi Feroz, glad you liked the API!

    I haven’t found anything in the Facebook Graph API that helps with what you ask for. My API is basically just a Java wrapper around the API. What is the use-case for adding existing test users to another application, rather than creating new test users?

  3. Aleadam

    Hi Tobias. From the updated fb doc page, :

    Adding existing test users to other apps
    You can add existing test users to other applications by using the Graph API with the application access token that you’re adding the user to.
    POST app_id/accounts/test-users?installed=true&permissions=read_stream
    uid : User id of the existing test user
    owner_access_token : Application access token of the app used to create the test user

    But I have actually another question that held the development (in java, developing with google app engine) for two days now and maybe you’ll know the answer: I sent app requests using the graph api from one test user to another. When the receiver test user accepts the request, it is redirected as expected to .
    But, in order to read that request, you need to provide the user access token for the receiving test user. Problem is, to get the access token, I need the user id, but I cannot query the user without the access token. So, I’m stuck without knowing who is accepting the request. I am trying an HTTPRequest sent to
    Oddly enough, the code in javascript works just fine without any access token
    FB.api(‘/me’, function(user) {
    alert (;

    Do you know how can I know the user id without resorting to redirect the servlet to a jsp page?

    Thanks in advance,


    1. Tobias Södergren

      Hi Aleadam, that looks like a nice feature. I’ll look into adding this functionality when I have the time.

      I don’t have an answer to the other question, but it sounds like it should be posted on the facebook forum:


  4. Aleadam


    Thanks for the reply.
    Indeed, I posted that on the forum and there’s even a bug report for the erratic behaviour of the app requests, but to date I got no answers whatsoever.
    I’ll have to figure out some workaround then.

  5. Shankar

    i am working in facebook java api, i want to get user email from facebook but dont know how to dot that can u pease help me out?

  6. Kalle Stenflo

    There is a typo in your code (or is it a facebook API change).

    facebookStore.createTestUser(true, “read-stream”)

    should be

    facebookStore.createTestUser(true, “read_stream”)


  7. Daniel Tkatch

    Since we configured our Facebook application to https creating the Facebook Test User does not work any longer using the com.jayway.facebooktestjavaapi.testuser

    “error”: {
    “message”: “Invalid redirect_uri: Given URL is not permitted by the application configuration.”,
    “type”: “OAuthException”

    Should it work also with the https apps?
    Can one run it in debug mode to find out where exactly does it fail?

  8. Hi Daniel, I haven’t tried with SSL-apps but I will look into it when I find time. The source code for the API is available on github and maven central if you want to debug.

  9. Graph Search seems like a great idea in theory Facebook
    has collected billions, maybe trillions of pieces of
    data about its users over the last nine years, and making that
    data searchable is a natural move.

Leave a Reply