Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkstyle warnings on throwing Throwables in Step Definitions #1207

Closed
filfreire opened this issue Aug 28, 2017 · 2 comments · Fixed by #1208
Closed

Checkstyle warnings on throwing Throwables in Step Definitions #1207

filfreire opened this issue Aug 28, 2017 · 2 comments · Fixed by #1208
Labels
good first issue Good for newcomers

Comments

@filfreire
Copy link

filfreire commented Aug 28, 2017

Summary

If a given Cucumber Java project uses CheckStyle, one of the warnings raised is the IllegalThrowsCheck for Step Definitions, because, by default, they throw a Throwable.

Expected Behaviour

We could try to improve the default throws of step definitions to ensure that types (Like Error or Throwable) are not declared to be thrown and are not allowed.

Current Behavior

The current behaviour is that by default, we allow throwing Throwables.

Context & Motivation

Like mentioned above, if a given Cucumber Java project uses CheckStyle and depends on its validations, a common failure is the throwing of Throwables.

@mpkorstanje mpkorstanje added the good first issue Good for newcomers label Aug 28, 2017
@mpkorstanje
Copy link
Contributor

mpkorstanje commented Aug 28, 2017

It is not required for a step definition to declare any exceptions. You can remove these or reduce their severity to satisfy your check style.

We can't disallow step definitions from throwing Throwable or declaring it as thrown but I am I'm assuming that you are using an IDE plugin which uses the SnippetGenerator to create your step definitions. By default the JavaSnippet declares Throwable in its template which is indeed more then it needs to be. Exception should be sufficient.

This should reduce the manual labor of fixing generated code somewhat.

mpkorstanje added a commit that referenced this issue Aug 28, 2017
Tests are allowed to fail by throwing an(y) exception. As such #318
added `throws Throwable` to the JavaSnippet. Aside from being a bad
practice this results in unnecessary checkstyle warnings. As such the
generated snippet should not explicitly declare `Throwable`.

Reducing `Throwable` to `Exception` should be sufficient.

Fixes #1207
@lock
Copy link

lock bot commented Oct 24, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants