1

测试在 mxunit 中返回结构数组的函数的最佳方法是什么?现在我正在做这样的事情:

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") && actual[i].name eq "getAccountName"){
        found = true;
        break;
    }
}

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

这感觉有点笨拙和脆弱。有人知道更好的方法吗?

4

1 回答 1

2

这就是我要做的:

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");
    }
}
于 2011-09-23T14:34:22.657 回答