Programmatic testbox tests - iteration over config

Hi, we have a multi tenancy setup and I would like to run tests based upon varying configuration.

So… get our list of client databases… get the desired configuration for that client… then run the same tests for each client… I don’t want to write tests for each of the 50 or so clients we have.

Is there a way of doing this within testbox. Something like this (not working)

component extends=“testbox.system.BaseSpec” {
function run() {
function beforeAll() {
variables.clients = [
{ id: 1, dataSource: “Client1” , clientName: ‘Client 1’}
,{ id: 2, dataSource: “Client2” , clientName: ‘Client 2’}
];
}
for (var client in variables.clients) {
(function(client) {
describe(“Running tests for client #client.clientName#”, function() {
beforeAll(function() {

                    });
                    it("Should run a test for client #client.clientName#", function() {
                        expect(true).toBeTrue(); 
                    });
                });
            })(client); 
        }
    }
}

In theory, this should work - and I’ve done similar in the past. There are a number of issues in your example, though, and the formatting is so bad I can’t even tell where one method stops and another stops.

Firstly:

  1. beforeAll() does not belong inside run(). This will never be executed. Move it outside the run() method.
  2. beforeAll() is also not supported inside a describe() method. YOu should use beforeEach() instead, if you really need it. (Since it’s an empty method, in your example, I would argue you do not.)
  3. There’s no need to do (function(client) {...}(client);. Why create the method if you’re going to call it immediately? This adds a pretty confusing additional layer to an already-complex test.
  4. I would avoid the variable name client due to the archaic client scope from Adobe /Lucee CFML.

Try this:

component extends="testbox.system.BaseSpec" {
    function beforeAll() {
        variables.clients = [
            { id: 1, dataSource: "Client1" , clientName: 'Client 1'},
            { id: 2, dataSource: "Client2" , clientName: 'Client 2'}
        ];
    }
    function run() {
        for (var client in variables.clients) {
            describe("Running tests for client #client.clientName#", function() {
                it("Should run a test for client #client.clientName#", function() {
                    expect(true).toBeTrue(); 
                } );
            } );
        }
    }
}