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

Add 'throws Exception' to generated Java stepdef snippets #318

Closed
pettermahlen opened this issue May 16, 2012 · 7 comments
Closed

Add 'throws Exception' to generated Java stepdef snippets #318

pettermahlen opened this issue May 16, 2012 · 7 comments

Comments

@pettermahlen
Copy link

The convention (or my convention at least - I think it is general) when writing unit tests is to have method signatures like this:

@Test
public void shouldDoSomethingSomeWay() throws Exception {
   // test code
}

This means you don't need to worry about catching any checked exceptions, and is a statement that 'any exceptions thrown out of this test means the test should fail'.

I think it is a good idea to do the same with step definitions. Would it make sense to add 'throws Exception' to the method signatures in Java snippets? I'll be happy to submit some code if so.

@aslakhellesoy
Copy link
Contributor

That makes total sense. throws Throwable even.

@pettermahlen
Copy link
Author

Seems I don't know how to make pull requests - issue 319 was created for this as well. :(

@baztian
Copy link

baztian commented Oct 24, 2014

Why did you choose to throw Throwable over Exception? Only classes deriving from Exception have to be added to the signature.

@aslakhellesoy
Copy link
Contributor

I can't remember now. throwing Exception should be fine.

@baztian
Copy link

baztian commented Oct 25, 2014

So wouldn't it be more appropriate to output "throw Exception" in the generated snippets? Or do you avoid that change as it doesn't look well in already established test suites?

@aslakhellesoy
Copy link
Contributor

Your suggestion sounds good. Please send a PR

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 25, 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 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants