[ 
https://issues.apache.org/jira/browse/LUCENE-7037?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15154348#comment-15154348
 ] 

Robert Muir commented on LUCENE-7037:
-------------------------------------

If we want to add one that takes message, I am fine. I did not do it here, 
because you get a clear exception (and if you expected a different one, it 
chains that incorrect one), and the test class and method name in the 
stacktrace should clarify what is wrong. I converted to comments if i felt 
those "messages" added additional context to document what the test is doing, 
but that is just that. 

These are not error messages to end-users but test failures for developers, who 
will go look at the source code. So I think we should focus on testing 
exceptions correctly (e.g. inspection of its message that its really the 
exception we expect), and documenting and organizing our tests to be clear in 
general, instead of adding infra to pass this around at runtime.

Along the multi-catch: I feel the same way. The other big one is different 
exception type (always wrapped in RejectedExecution or something) when 
IndexSearcher uses an Executor. That is not good.

> Switch all exception tests to expectThrows()
> --------------------------------------------
>
>                 Key: LUCENE-7037
>                 URL: https://issues.apache.org/jira/browse/LUCENE-7037
>             Project: Lucene - Core
>          Issue Type: Bug
>            Reporter: Robert Muir
>         Attachments: LUCENE-7037.patch
>
>
> Tests expecting exceptions today are done in various ways.
> The best ones look like this.
> {code}
> try {
>   something();
>   fail("message");
> } catch (Exception expected) {
>   assertSomethingAbout(expected);
> }
> {code}
> But there are many forms (involving booleans and such). All of these are a 
> little sketchy because it is all-too easy to just forget the {{fail()}} and 
> then the whole test is useless.
> `expectThrows` was added in LUCENE-7009 which solves a lot of these problems. 
> Its not perfect, but overall a big improvement. We should cut over all of our 
> tests.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to