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 に答える