[
https://issues.apache.org/jira/browse/HDDS-9956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17814276#comment-17814276
]
Attila Doroszlai commented on HDDS-9956:
----------------------------------------
Thanks [~wangzhaohui] for the question. I think it's the opposite.
Rationale:
* {{fail}} is an assertion, has the same effect as {{assertTrue(false)}}
* some tools warn if a test does not have any assertions
* therefore, if {{fail}} is the only assertion in the test (your second
example), we should add {{assertDoesNotThrow}}
* otherwise, if there are other assertions (your first example), kept after
removing {{try-catch-fail}}, then we don't need to add {{assertDoesNotThrow}}
* {{assertDoesNotThrow}} can be added in both cases, it's just not strictly
necessary for the second case
> Simplify tests using assertThrows
> ---------------------------------
>
> Key: HDDS-9956
> URL: https://issues.apache.org/jira/browse/HDDS-9956
> Project: Apache Ozone
> Issue Type: Improvement
> Components: test
> Reporter: Attila Doroszlai
> Assignee: Zhaohui Wang
> Priority: Major
>
> Tests of the following form can be simplified:
> {code}
> try {
> <some action>
> fail()
> } catch (Exception e) {
> assertTrue(e instanceof <SpecificException>)
> <further assertions>
> }
> {code}
> to:
> {code}
> Exception e = assertThrows(<SpecificException>.class,
> () -> <some action>);
> <further assertions>
> {code}
> {{e}} can be declared as {{<SpecificException>}} if its specific properties
> need to be verified (e.g. {{OMException#getResult()}}). Otherwise I suggest
> using {{Exception}} for shorter and more uniform code.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]