开发者

Testing an array of structures in mxunit

What is the best way to test a function that returns an array of structres in mxunit? Right now i'm doing something like this:

var actual = variables.pbj.getFunctions();  //returns [{name="getAccountNumber", value="0"},{name="getAccountName", value=""}]
var found = false;

//look for get account number
for(var i = 1; i lte arrayLen(actual); i ++){
    if(structKeyExists(actual[i],"name") && actual[i].name eq "getAccountNumber"){
        found = true;
        break;
    }
}

if(NOT found){
    fail("Struct key getAccountNumber didn't exist");
}

    found = false;

//look for account name
for(var i = 1;i lte arrayLen(actual); i ++){
    if(structKeyExists(actual[i],"name") && ac开发者_Go百科tual[i].name eq "getAccountName"){
        found = true;
        break;
    }
}

if(NOT found){
    fail("Struct key getAccountName didn't exist");
}

This feels somewhat kludgy and fragile. Anybody know of a better way?


This is what I would do:

var actual = variables.pbj.getFunctions();  //returns [{name="getAccountNumber", value="0"},{name="getAccountName", value=""}]

for (thisStruct in actual) {
    if(NOT structKeyExists(thisStruct,"name") || thisStruct.name neq "getAccountNumber"){
        fail("Struct key getAccountNumber didn't exist");
    }
    if(NOT structKeyExists(thisStruct,"name") || thisStruct.name neq "getAccountName"){
        fail("Struct key getAccountName didn't exist");
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜