Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting Groovy脚本在运行测试套件时保持运行_Sorting_Groovy_Ready Api - Fatal编程技术网

Sorting Groovy脚本在运行测试套件时保持运行

Sorting Groovy脚本在运行测试套件时保持运行,sorting,groovy,ready-api,Sorting,Groovy,Ready Api,在运行整个套件时,我遇到了groovy脚本的异常行为。我有一个脚本,它在我的测试用例运行之前按字母顺序排列,即使整个测试套件完成,它似乎也会永远运行 在我点击它查看详细信息并立即返回测试套件后,它显示它已经完成并且不再运行 请问我的剧本有什么问题吗?我没有看到任何无限循环或类似的东西。这只是ReadyAPI中的一个bug吗?谢谢你的建议 我的排序脚本: ArrayList<String> testCaseList = new ArrayList<String>(); f

在运行整个套件时,我遇到了groovy脚本的异常行为。我有一个脚本,它在我的测试用例运行之前按字母顺序排列,即使整个测试套件完成,它似乎也会永远运行

在我点击它查看详细信息并立即返回测试套件后,它显示它已经完成并且不再运行

请问我的剧本有什么问题吗?我没有看到任何无限循环或类似的东西。这只是ReadyAPI中的一个bug吗?谢谢你的建议

我的排序脚本:

ArrayList<String> testCaseList = new ArrayList<String>();
for (testCase in testRunner.testCase.testSuite.getTestCaseList()) {
 testCaseList.add(testCase.getName());
}
testCaseList.sort();
int i = 0;
for (tCase in testCaseList) {
 def curCase = testRunner.testCase.testSuite.getTestCaseByName(tCase);
 curIndex = testRunner.testCase.testSuite.getIndexOfTestCase(curCase); 
 testRunner.testCase.testSuite.moveTestCase(curIndex,i-curIndex);
 i++; 
}
ArrayList testCaseList=new ArrayList();
for(testRunner.testCase.testSuite.getTestCaseList()中的testCase){
add(testCase.getName());
}
testCaseList.sort();
int i=0;
for(测试用例列表中的tCase){
def curCase=testRunner.testCase.testSuite.getTestCaseByName(tCase);
curIndex=testRunner.testCase.testSuite.getIndexOfTestCase(curCase);
testRunner.testCase.testSuite.moveTestCase(curIndex,i-curIndex);
i++;
}

目前,您似乎有单独的测试用例进行排序。但实际上,这不是您的有效测试用例

因此,要做的第一个更改是脚本应该从测试用例移动到测试套件的
设置脚本

下面是测试套件的设置脚本,它按字母顺序进行设置。应特别注意,如果测试用例名称中有数字,则必须按自然顺序排列。否则,应该可以

请遵循在线评论

//Get the sorted order of the test case which is expected order
def newList = testSuite.testCaseList.name.sort()
log.info "Expected order of test cases: ${newList}"

//Get the current index of the test case
def getTestCaseIndex = { name -> testSuite.getIndexOfTestCase(testSuite.getTestCaseByName(name))}

//Closure definition and this is being called recursively to make the desired order
def rearrange
rearrange = {
    def testCaseNames = testSuite.testCaseList.name
    if (testCaseNames != newList) {
        log.info testCaseNames
        newList.eachWithIndex { tc, index ->
            def existingIndex = getTestCaseIndex(tc)
            if (index != existingIndex) {
                testSuite.moveTestCase(index, existingIndex-index)
                rearrange()
            }
        }
    } else {
        log.info 'All cases sorted'
    }
}

//Call the closure
rearrange()
使用该
设置脚本
,当执行测试套件时,测试用例会自动按字母顺序移动。因此,订购时不需要单独的测试用例


现在,套件将使用所需的测试用例执行,问题中提到的当前问题根本不存在。

目前,您似乎有单独的测试用例进行排序。但实际上,这不是您的有效测试用例

因此,要做的第一个更改是脚本应该从测试用例移动到测试套件的
设置脚本

下面是测试套件的设置脚本,它按字母顺序进行设置。应特别注意,如果测试用例名称中有数字,则必须按自然顺序排列。否则,应该可以

请遵循在线评论

//Get the sorted order of the test case which is expected order
def newList = testSuite.testCaseList.name.sort()
log.info "Expected order of test cases: ${newList}"

//Get the current index of the test case
def getTestCaseIndex = { name -> testSuite.getIndexOfTestCase(testSuite.getTestCaseByName(name))}

//Closure definition and this is being called recursively to make the desired order
def rearrange
rearrange = {
    def testCaseNames = testSuite.testCaseList.name
    if (testCaseNames != newList) {
        log.info testCaseNames
        newList.eachWithIndex { tc, index ->
            def existingIndex = getTestCaseIndex(tc)
            if (index != existingIndex) {
                testSuite.moveTestCase(index, existingIndex-index)
                rearrange()
            }
        }
    } else {
        log.info 'All cases sorted'
    }
}

//Call the closure
rearrange()
使用该
设置脚本
,当执行测试套件时,测试用例会自动按字母顺序移动。因此,订购时不需要单独的测试用例


现在,该套件使用所需的测试用例执行,问题中提到的当前问题根本不存在。

对于调试,只需注释掉函数的行,看看会发生什么。Dropout,请检查解决方案,看看是否解决了问题?对于调试,只需注释掉函数的行,看看会发生什么。退出,请检查解决方案,看看是否解决了问题?由于某种原因,结果太混乱,导致ReadyAPI错误,迫使我重新加载项目。但这对我来说可能是个问题。无论如何,正如您所说的,将我的脚本作为设置脚本非常有效,解决了我的问题。非常感谢你的帮助!由于某种原因,这变得太混乱,导致ReadyAPI出现错误,迫使我重新加载我的项目。但这对我来说可能是个问题。无论如何,正如您所说的,将我的脚本作为设置脚本非常有效,解决了我的问题。非常感谢你的帮助!