Skip to content

Fixes bug in unit tests that meant exceptions were being "hidden" from callables and uses unchecked instead of checked exceptions #7

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

Closed
wants to merge 7 commits into from

Conversation

michaelruocco
Copy link
Contributor

I was attempting to write a pull request to wrap the throwing of checked exceptions so that I don't have to add a throws Exception clause to the end of all my tests. I will also raise a PR for this shortly, however in doing so I came across a small bug in the unit tests for the scenario where a callable throws an exception.

The first commit in this PR shows how the bug can be recreated, I was expected the tests to receive an exception when I added the catchThrowable but they didn't. The second commit fixes the issue by removing the extra nesting levels for the lambda.

I also added an explicit version for the maven surefire plugin into the POM as I found when trying to run the tests this was failing for me since I didn't have the latest version.

Neither are big issues but since I came across them I thought I would share what I found.

@michaelruocco
Copy link
Contributor Author

I have now added three more commits which implement the change I was originally intending to raise, this updates the execute method signatures for callable and statement so that a checked exception is no longer declared as being thrown. I have updated the method implementation to wrap the checked exception in an unchecked exception. The reason why I wanted this was that in the majority of the tests where I have used this library so far I am testing success cases rather than failure cases, and I personally it was a little annoying to have to add a throws Exception clause to all my tests. I really like the library so I thought I would have a go at updating it myself, and I found it very easy to do as it is very well written and tested, so thanks very much for sharing.

@michaelruocco michaelruocco changed the title Fixes bug in unit tests that meant exceptions were being "hidden" from callables Fixes bug in unit tests that meant exceptions were being "hidden" from callables and uses unchecked instead of checked exceptions Aug 30, 2020
@@ -1,2 +1,4 @@
.flattened-pom.xml
target
.idea
*.iml
Copy link
Owner

@stefanbirkner stefanbirkner Aug 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be part of your personal global gitignore file. From the git docs:

Patterns which a user wants Git to ignore in all situations (e.g., backup or temporary files generated by the user’s editor of choice) generally go into a file specified by core.excludesFile in the user’s ~/.gitconfig.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay nice, ill take a look at setting this up, thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be done that way, though it's probably a nicety to allow it in the repo too.

@stefanbirkner
Copy link
Owner

stefanbirkner commented Aug 30, 2020

Thanks for the PR. I'm still undecided whether I want to have shorter stack traces in case of a failure or avoid the throws Exception in the signature of test methods. I have to play around with it a little bit.

pom.xml Outdated
@@ -67,6 +67,7 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I extracted this to a single commit 416ca75 because I like to have one commit per change so that its purpose can be explained in the commit message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure no problem, I probably should have done that in the first place anyway.

@michaelruocco
Copy link
Contributor Author

Id have preferred not to have to re-throw Exception from each of my test but its not a big enough annoyance to diverge from using this version. Since the other elements have already been added to master now I have closed this down.

@ashleyfrieze
Copy link
Contributor

@michaelruocco see whether https://github.com/webcompere/system-stubs is a reasonable alternative. You can avoid using the wrapper methods that throw and just plug in via a JUnit extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants