Sign In Register

How can we help you today?

Start a new topic

Running cloud code Requests does nothing in Unit Tests (Unity)


I'm trying to write a Unit Test which would make a request to GS, such as RegistrationRequest.

However, when the code runs inside the C# Unit Test as part of the Unity Test Runner, literally nothing happens.

The Request() call executes but there is no errors and the callback never fires. The exact same code runs fine in the game when the game is running.

Is there some additional setup needing to be done within Unit Tests to get cloud code to execute?

Thank you!


Hi Drew,

If a request is sent from Unity the Cloud Code for it will run server side. If the request isn't reaching us then the Cloud Code won't execute. What exactly is it you are trying to test here ? 



1 person likes this

hi Liam,

I am sending the request, but the Cloud Code doesn't seem to ever be called. The callback on the AuthenticationRequest never fires, and there's no error in the error logs either.

This exact same code works 100% perfectly actually in-game. Only in the C# unit test inside Unity does this behavior appear.

Any idea if there's some setup I'm supposed to do in Unit Tests for the requests to fire properly? No exception is being thrown on the client side.. See my code below:


        public void AuthenticationRequest(string username,string password, Action<AuthenticationResponse> response)    
            var req = new AuthenticationRequest();

            .Send((resp) =>
                string mesg = null;

                if (resp.HasErrors)
                    var errorDetail = resp.Errors.GetString("DETAILS");

                    if (errorDetail == "UNRECOGNISED")
                        mesg = "Invalid Username and/or Password";
                    else if (errorDetail == "LOCKED")
                        mesg = "This account has been locked out. Please try again later.";

                response(new AuthenticationResponse(mesg, resp.HasErrors));


bump!! can anyone help? How do I write C# unit tests which will call out to the GameSparks API?

I guess I could make my own "TestScene" with buttons which would run the tests. But then I won't be able to use the Unity test runner, which would suck.

Any other ideas?

 Hey Drew,

I'm not familiar with unity test runner, but it sounds like the SDK isnt setup when you run the code.
You'll have to have the editor establish a websocket connection while the test is being preformed. Our SDK is currently not setup to handle this.
Another option (so long as this is only for testing, and never goes into the client app) is to use a rest call to the same request for testing while using the websocket when the game is running.

Sorry i couldnt be more helpful.

Login to post a comment