在 mxunit 中测试结构体数组
测试返回 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是我要做的:
This is what I would do: