Reputation: 21
I want to know how many steps failed on specific test cases and save it to a database. I already have a database.
My question now is how to save the number of test cases that failed in a test suite?
Upvotes: 2
Views: 428
Reputation: 8414
This is the answer to the second question: how to obtain the number of test cases that failed/passed on a test suite run.
I have 3 test cases named Test Case 1, 2, and 3 respectively. They are simple, they have just assert false
or assert true
as their steps, as seen in the screencap.
Test Suite 1 contains all of the above cases.
Create a listener (right-click on Test Listeners [#1 in image] > New > New Test Listener) with the following two checkboxes selected:
and add this to code:
class Listener {
@AfterTestCase
def sampleAfterTestCase(TestCaseContext testCaseContext) {
if(testCaseContext.getTestCaseStatus()=='PASSED') {
GlobalVariable.numOfPasses++
}
if(testCaseContext.getTestCaseStatus()=='FAILED') {
GlobalVariable.numOfFails++
}
}
@AfterTestSuite
def sampleAfterTestSuite(TestSuiteContext testSuiteContext) {
println 'Passes:' +GlobalVariable.numOfPasses
println 'Failures:' +GlobalVariable.numOfFails
}
}
Under Profiles > default [#2 in the first image] add two numeric variables numOfPasses
and numOfFails
and set them both to 0.
Running the above setup will give you total number of failed/passed tests:
Passes:1
Failures:2
Upvotes: 1