Forum Discussion

pembertonrw's avatar
pembertonrw
Contributor
12 years ago

[Resolved] Failing Script Assertion Step on Test Step

I have a script assertion step that asserts a load of values that are returned in a response to a request. Currently I am passing in a map with three properties:

* Property Name
* ActualResult
* ExpectedResult

Most of the values that are returned are randomly generated by the test so what I want to do is to fail the test step with a prettier error. I have tried


resultsToCheckMap.each()
{
try
{
assert it.get('ExpectedResult') == it.get('ActualResult')
}
catch(AssertionError e)
{
context.testRunner.fail("Actual result did not match expected result for Property: " + it.get('PropertyName') + "Actual: " + it.get('ActualResult') + "ExpectedResult: " + it.get('ExpectedResult'))
}
}


which works OK but will only fail properly if the test case is ran but not when the test step is being ran manually.

So what I would like to do is just cause the script assert to fail with the more prettier error.
  • Ended up solving this by throwing a new exception so the groovy I used was:

    resultsToCheckMap.each()
    {
    try
    {
    assert it.get('ExpectedResult') == it.get('ActualResult')
    }
    catch(AssertionError e)
    {
    throw new Exception("Actual result did not match expected result for Property: " + it.get('PropertyName') + "Actual: " + it.get('ActualResult') + "ExpectedResult: " + it.get('ExpectedResult'))
    }
    }
  • Happy to hear you solved the problem. Thanks for sharing the solution.