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

Question about expecting exceptions #127

Closed
paulyoung opened this issue Jul 30, 2015 · 6 comments
Closed

Question about expecting exceptions #127

paulyoung opened this issue Jul 30, 2015 · 6 comments

Comments

@paulyoung
Copy link
Contributor

Would it possible to expect exceptions via attributes?

Borrowing from NUnit, this might look like:

[<Property(ExpectedException="exn")>]

or

[<Property>]
[<ExpectedException("exn")>]
@paulyoung
Copy link
Contributor Author

To clarify, this would allow:

[<Property(ExpectedException="exn")>]
let ``failure`` (e: exn) =
  Failure e |> dematerialize

vs

[<Property>]
let ``failure`` (e: exn) =
  Prop.throws<exn, _> (lazy (Failure e |> dematerialize))

@ploeh
Copy link
Member

ploeh commented Jul 30, 2015

If this idea is the same as MSTest's [ExpectedException] attribute, everyone pretty much agrees that it was a bad idea. Here's one explanation: http://hadihariri.com/2008/10/17/testing-exceptions-with-xunit

I don't think it'd be a good idea to perpetuate a bad idea when there are better options around.

BTW, you should consider looking at Unquote for expressing assertions.

@paulyoung
Copy link
Contributor Author

Thanks @ploeh, I'll look into that.

I tried using Unquote but it had some limitations that meant it wasn't an option for me.

@ploeh
Copy link
Member

ploeh commented Jul 30, 2015

BTW, I hope the above comment wasn't too crass. I was on my way out the door when I wrote it, but now that I reread it, I think it looks a little impolite. If so, please accept my apologies.

@paulyoung
Copy link
Contributor Author

Not at all! Nice to hear from you.

@kurtschelfthout
Copy link
Member

Yeah, not a fan of that suggestion either. Been bitten a few too many times by overly broad attribute-based ExpectedException mechanisms.

Most unit testing frameworks should have support for somethink like Assert.Throws<ArgumentException(fun () -> ...) nowadays anyway. If not, it's easy to write.

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

No branches or pull requests

3 participants