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

Allow overloaded verify() method that takes arbitrary text message #202

Closed
markberry opened this issue Jul 23, 2018 · 4 comments
Closed
Labels

Comments

@markberry
Copy link

Please provide any additional information below.

In most testing frameworks, the assert call comes in two varieties: assert(condition) and assert(message, condition), where the message gets included in the output if the condition fails.

In EqualsVerify, the verify() call is effectively the same as an assert call, but this only comes in a single variety.

It would be most useful if I could call verify with an arbitrary text message that was used as a prefix for any exception that the test throws.

(In practice, the most common use of this message would likely be to pass in foo.class.getSimpleName() when testing foo.class, but I recognize that not everyone would want this as the default, hence the suggestion to allow an arbitrary message).

@jqno
Copy link
Owner

jqno commented Jul 25, 2018

Hi! Thanks for reporting this.
It sounds like an interesting idea, but I don't see the general application for this. The reason why this feature exists in assert* methods in test frameworks, is to give a more clear error message, but EqualsVerifier's error messages are already quite verbose.

You say you would most often use it with the getSimpleName of the class you're testing. Wouldn't it be much simpler if EqualsVerifier just always included that?

Can you give me an example of where adding your own text would be useful?

@markberry
Copy link
Author

If the error message always included the getSimpleName then that would certainly go a long way to making my life easier, but I was slightly wary of suggesting just that, in case making that change affected existing users of the library in some way I hadn't thought of.

My full use case is that I have a table of classes that my test has to loop over, using EqualsVerify on each, and without having the name of the class in the message, I can't tell which class actually has a problem. The table of classes to be tested is built outside of the test (something akin to a plug-in architecture), and sometimes different plug-in providers use the same simpleName for their class. Whilst the full class name is unique, that is often very verbose, and I'd rather build a distinct but short string from the plug-in reference and the simpleName, and provide that as an arbitrary string.

@jqno
Copy link
Owner

jqno commented Jul 26, 2018

That sounds like a good use case, and adding the simpleName in every error message shouldn't be a problem.

It could indeed theoretically affect existing users, so I'll include it in the next major release (which I'm already working on).

@jqno
Copy link
Owner

jqno commented Sep 26, 2018

I've just released version 3.0, where the simpleName is now included in all error messages.

@jqno jqno closed this as completed Sep 26, 2018
akhalikov pushed a commit to akhalikov/equalsverifier that referenced this issue Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants