在 mxunit 中测试结构体数组

发布于 2024-12-05 22:32:28 字数 829 浏览 0 评论 0原文

测试返回 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");
}

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

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") && actual[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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撞了怀 2024-12-12 22:32:28

这就是我要做的:

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");
    }
}

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");
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文