oshdb icon indicating copy to clipboard operation
oshdb copied to clipboard

try-catch blogs for “relaxed” tests

Open joker234 opened this issue 5 years ago • 0 comments

Q/A (from #283) relating to e.g. https://github.com/GIScience/oshdb/blob/c637936209abe4834f751e4f16cec350ae49e7fc/oshdb-util/src/test/java/org/heigit/bigspatialdata/oshdb/util/geometry/osmhistorytestdata/OSHDBGeometryBuilderTestOsmHistoryTestDataRelationNotMultipolygonTest.java#L473-L483

What is the need or requirement for the many try-catch blocks that just throw the exception again in tests?

As far as I remember, for some of the test cases we said that we really don't care about how exactly a certain corner case situation is handled as long as the code does not crash with an exception (e.g. when the uid field is missing, then we don't care if it is filled with 0, -1` or any other imaginable value).

But if you just write a test without the try-catch->fail statement, tools like SonarLint complain that each test should have at least one assert statement. Maybe there's a better way to write such a "relaxed" test? thinking adding a @SuppressWarnings("java:S2699") can silence the warnings, but adding @Test(expected = Test.None.class /* no exception expected */) (see https://stackoverflow.com/a/44801486/1627467) might be more explicit way to state this (even though IntelliJ then suggests to remove the default parameter assignment shrug ).

This wasn't solved in #283. Think about it and solve or close this issue.

joker234 avatar Dec 07 '20 15:12 joker234