Sign In Register

How can we help you today?

Start a new topic

Automated test framework for cloud code


it would be great if there could be support for automated (unit / integration) tests for cloud code, both regular api and RT, with dummy Spark / RTSession object injected.

for example I would like to have a "game_test" script alongside my game RT script that runs every time I save/import my scripts,  it in which I could say (example)


test("when a player sends packet 1, it responds with packet 2", function(dummyRTSession) {
    // arrange
    var player = dummyRTSession.connectPlayer(); // triggers onPlayerConnect with random id and progressive peerId
    // act
    player.sendPacket(1, dummyRTSession.newData().setNumber(1, 42)); // (opCode, data)
    // assert
    Assert.that(dummyRTSession.received(1).sendPacket(2, function(data) {/*check expected contents*/}));
   Assert.that(dummyRTSession.getScript().getState("myGlobal") == "something");

   (i'm mixing various frameworks' syntax here, it's just an example)

and similar stuff for requests/response/messages/modules, with fake Spark.* injected

they should run either when I save or import my scripts from git, or manually through the dashboard, and either reject or warn when a test fails

(if there is already a way to do automatic tests that I missed, please point me to that)

3 people like this idea

Hi Mauro,

Currently there is no automated test frame work in place. It's something we can raise with the dev team for you. I know some users have created modules to handle requests and responses by use SparkRequests to send then as a specific player and perform actions depending on the results. Thanks for logging the feature request.




could you highlight me on this? I put most of our (non-RT) code in modules, so that could be interesting to look at. (I have setup some manual test events for stuff that doesn't use Spark.* API in cloud code but it's only a minimal part)

it would be more useful is for the RT script, that now is a single monolithic block that has to be "tested" by running games manually and hoping that any potential race condition is handled right.

non-RT cloud code can benefit on this so we can test that my script would write the right row in the right collection without actually polluting the DB

Hi Mauro,

I've posted a very basic example of this using the AccountDetailsRequest. You could use any other custom LogEventRequest for this.


//use a SparkRequest to send the event as a player
//playerID is the id of the player you want to send the event as

var request = new SparkRequests.AccountDetailsRequest();
var response = request.SendAs(playerID);

//use ExecuteAs(playerID) if your event has Cloud Code which you would like to execute as the given player. SendAs simply send the event without executing the Cloud Code for that script.

//check if currency1 is >= to 100
var currency1 = response.currency1; 

if(currency1 >= 100){
//do this


You can then run send some more SparkRequests based on the values retrieved from the responses. You could also test with values stored in a collection to replicate a more specific scenario. Does that make sense ? If you have any further questions just let us know.



Login to post a comment