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

Closed
pettermahlen opened this Issue May 16, 2012 · 6 comments

Comments

Projects
None yet
3 participants
@pettermahlen

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

This comment has been minimized.

Show comment Hide comment
@aslakhellesoy

aslakhellesoy May 16, 2012

Owner

That makes total sense. throws Throwable even.

Owner

aslakhellesoy commented May 16, 2012

That makes total sense. throws Throwable even.

@pettermahlen

This comment has been minimized.

Show comment Hide comment
@pettermahlen

pettermahlen May 16, 2012

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

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

@baztian

This comment has been minimized.

Show comment Hide comment
@baztian

baztian Oct 24, 2014

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

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

This comment has been minimized.

Show comment Hide comment
@aslakhellesoy

aslakhellesoy Oct 24, 2014

Owner

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

Owner

aslakhellesoy commented Oct 24, 2014

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

@baztian

This comment has been minimized.

Show comment Hide comment
@baztian

baztian 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?

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

This comment has been minimized.

Show comment Hide comment
@aslakhellesoy

aslakhellesoy Oct 25, 2014

Owner

Your suggestion sounds good. Please send a PR

Owner

aslakhellesoy commented Oct 25, 2014

Your suggestion sounds good. Please send a PR

mpkorstanje added a commit that referenced this issue Aug 28, 2017

Reduce Throwable to Exception in JavaSnippet
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment