browser icon indicating copy to clipboard operation
browser copied to clipboard

Allow setting custom failure messages

Open wouterj opened this issue 4 years ago • 4 comments

PHPUnit's asserts (and all asserts provided by Symfony) allow you to specify a custom failure message as last argument. This gives you the possibility to add some more context to an otherwise vague error.

Would it be an idea to also add this feature to Browser?

wouterj avatar Jan 05 '21 16:01 wouterj

I thought about this but decided against for the following reasons:

  1. Dusk doesn't provide this option (see https://github.com/laravel/dusk/issues/206)
  2. Some assertions make multiple "sub" assertions - should I use the message to override all these?
  3. Removes the possibility of adding extra optional method arguments in the future
  4. I don't think I've ever used custom messages in phpunit

This all being said I don't have a strong opinion on this.

kbond avatar Jan 05 '21 18:01 kbond

I also rarely use this feature with PHPUnit, but in some cases it's very handy to help my future self.

I understand why you've decided against, but is there another way to output a message, perhaps with a method that follows the assertion? Something like:

->assertSee('23rd January 2023')
->reportOnFailure('The date of the reservation is not correct')

It's just an idea and it's not the end of the world if we can't do this - just have to add a comment in the test source code and then go look that up on failure so no drama really.

benr77 avatar Jan 10 '23 08:01 benr77

I'm fine adding extra optional messages to the assertion methods.

Some assertions make multiple "sub" assertions - should I use the message to override all these?

Still not sure how we'd handle these.

Removes the possibility of adding extra optional method arguments in the future

The api is pretty stable so this isn't much of a concern anymore.

perhaps with a method that follows the assertion

That would be tough because the assertion happens in the method above. Do you have an idea on how this could work??

kbond avatar Jan 10 '23 15:01 kbond

That would be tough because the assertion happens in the method above. Do you have an idea on how this could work??

Not at all it was just a throwaway suggestion :)

benr77 avatar Jan 10 '23 15:01 benr77