haf / expecto

A smooth testing lib for F#. APIs made for humans! Strong testing methodologies for everyone!
Apache License 2.0
663 stars 96 forks source link

Make expectation message string optional #361

Closed PhilT closed 4 years ago

PhilT commented 4 years ago

In other test frameworks, it's not a requirement to have a message string for each expectation. In many scenarios it is redundant.

I'm new to F# and Expecto so perhaps this would break something but it'd be nice to be able to do something like:

Expect.equal (1 + 1) 2

From what I've seen, Expecto generates a suitable message if failure occurs.

FoggyFinder commented 4 years ago

Exactly. Messages are very clear by themselves and for many cases there is no need in any additions.

haf commented 4 years ago

You can just define:

module Expect =
  let equal a b = b |> Expect.equal "" a

So I think I'll mark this as won't-fix since it's pretty quick to add a "" after your sample or do the above.

haf commented 4 years ago

That said, I have a huge improvement inbound, and if this is still an issue after that we can look into it.

PhilT commented 4 years ago

Thanks. I thought there might be a simple workaround.

Cool! Looking forward to the updates.

rahicks26 commented 3 years ago

Just following up, to see if these would still be a nice feature? Our team is really interested in it and we would be willing to contribute.

haf commented 3 years ago

@rahicks26 What's your thinking? Making all functions overloaded? Perhaps we can talk API surface area a bit before we move forward?

rahicks26 commented 3 years ago

I hadn't given it too much thought just yet to be honest. Let me review it a bit this week and get back to you. We love the project and it has really helped us a lot here recently.

rahicks26 commented 3 years ago

@haf So after some review, we might be able to solve this by making it possible for tests to return unit or string->unit. Not sure if that is being tracked somewhere else or not. We can assume if string -> unit is returned the default message should be an empty string.

I haven't looked too deep into it, but property-based tests appear to be working with or without the message at least in some cases.

haf commented 3 years ago

The thing with that suggestion (returning a function string -> unit) is that you can't vary the return type of functions in F#, and besides that, it would only work if you only have a single assert that is also the last expression of the function.

Feel free to play around and see if you can find an API that works, it would be interesting to see.

lydell commented 3 years ago

Hi! Sorry for posting in this old thread. Are there any examples out there with inspiration on what what to write in the message parameter? My mind always goes blank on it, and I’m wondering if I’m missing out on something.

haf commented 3 years ago

Have a look at https://github.com/logary/logary 's test suite — perhaps that can give you some inspiration?