Added validation that all datapoint methods and fields are public and static to theory initialization #623
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes #125. In that issue, tests with non-static or non-public datapoint methods are ignored because they're not checked for when constructing the instance, and when the values are retrieved for theory parameters in getValue() in MethodParameterValue (in AllMembersSupplier) an exception is thrown, but then swallowed in addMultiPointMethods/addSinglePointMethods in AllMembersSupplier.
There's another abandoned pull request trying fixing this in #328, which rethrows all exceptions thrown in datapoint methods, including this one. This is arguably dubious since you could potentially have other exceptions coming from datapoint methods, and it's not clear whether those should actually fail tests. This commit does not affect issue 137 (caused by the exception hiding), which #328 does try to solve.
On the other hand, datapoint methods that are definitely being entirely ignored are a legitimately incorrect use of the datapoints annotation, and that should actually fail, I think.
While there was no error before this for non-static datapoint methods, there was an initialization error for non-static/non-public
@DataPoint
fields. There wasn't an error for@DataPoints
array fields though, for no possible good reason I can see, since this doesn't have any of the same exception hiding issues as the methods do.With this commit all of the above is fixed, by adding checks on test initialization that look at all the datapoint methods and fields, and confirms that they're public and static. This already existed for fields annotated with
@DataPoint
, but now also covers array fields annotated with@DataPoints
and array and singleton annotated datapoint methods.