Forum Discussion
msimmerson
14 years agoOccasional Contributor
Hi
Ok, so I sorted this myself and here is the Groovy Script to do it.
Basically, the code gets a handle to the workspace which then has access to all the projects in the workspace. Each project then navigates its way through every test suite and test case that belongs to that project.
Simple when you know how!!!
Cheers
Matt
def projectWS = project.workspace
def projectList = projectWS.projectList
def errorCount = 0;
for (int i = 0; i < projectList.size; i++) {
if (!projectList.path.contains("UnitTests")) {
def testSuiteList = projectList.testSuiteList
for (int j = 0; j < projectList.testSuiteCount; j++) {
def testCaseList = testSuiteList[j].testCaseList
log.info("Running Test Cases for " << testSuiteList[j].label)
for (int k = 0; k < testSuiteList[j].testCaseCount; k++) {
def testCaseRunner = testCaseList[k].run(context, false)
if (testCaseRunner.status != testCaseRunner.status.valueOf("FINISHED")) {
log.error("Test Case " << testSuiteList[j].label << ":" << testCaseList[k].label << " FAILED. Status was:" << testCaseRunner.status)
errorCount++;
}
}
}
}
}
if (errorCount == 0) {
log.info("All Tests PASSED");
} else {
log.info("" << errorCount << " tests FAILED");
}
Ok, so I sorted this myself and here is the Groovy Script to do it.
Basically, the code gets a handle to the workspace which then has access to all the projects in the workspace. Each project then navigates its way through every test suite and test case that belongs to that project.
Simple when you know how!!!
Cheers
Matt
def projectWS = project.workspace
def projectList = projectWS.projectList
def errorCount = 0;
for (int i = 0; i < projectList.size; i++) {
if (!projectList.path.contains("UnitTests")) {
def testSuiteList = projectList.testSuiteList
for (int j = 0; j < projectList.testSuiteCount; j++) {
def testCaseList = testSuiteList[j].testCaseList
log.info("Running Test Cases for " << testSuiteList[j].label)
for (int k = 0; k < testSuiteList[j].testCaseCount; k++) {
def testCaseRunner = testCaseList[k].run(context, false)
if (testCaseRunner.status != testCaseRunner.status.valueOf("FINISHED")) {
log.error("Test Case " << testSuiteList[j].label << ":" << testCaseList[k].label << " FAILED. Status was:" << testCaseRunner.status)
errorCount++;
}
}
}
}
}
if (errorCount == 0) {
log.info("All Tests PASSED");
} else {
log.info("" << errorCount << " tests FAILED");
}