0

Actually I'm writing a bunch of tests but I'm not sure how I should handle exceptions/errors best.

There a different types of exceptions, e.g. AssertException if a result was not as expected using assertThat(..). This is O.K. and understandable.

But what if I have a FileNotFound / SOAPException / DOMException and so on...?

For example in my @BeforeStory method I create some testdata by reading testfiles and sending them to a webservice and there I could possibly get the above mentioned exceptions. I would like to present these errors by using an own error message also in the living documentation. But how should I manage this? Actually I'm thinking about two approaches:

1.) I catch the exception and throw my own new exception with an individual error message. The testexecution is aborted for the scenario and the exception is presented in the living documentation.

2.) I catch the exception, implement a string based return statement with the error message and use an assertThat(...) in my low-level specifications so I only should get AssertException in the end.

3.) ..?

Question: And advice or common best practices how to handle exceptions or errors with selenium/serenity ?

4

1 回答 1

1

首先,有一个很好的主题信息来源——xUnit 测试模式书。

回答您的问题,好的方法是使用 2 组主要错误。第一个是 AssertionException,表示被测应用程序中存在问题(错误)。第二个是所有其他异常,表明测试代码本身、测试执行环境或应用程序环境存在问题,但应用程序中没有。以这种方式构建测试将帮助您快速发现和消除问题。

所以一般来说,你的第一个选择是正确的。当异常发生时收集一些额外的数据(例如应用程序/执行环境)是一个好主意。

于 2015-09-09T07:09:53.187 回答