Assertion wrapper in Java
I want to use the assertion in production code to validate the input for private methods as this article recommends: Assertion best practices.
And I'm looking for a good thin wrapping code that i can use. I'm sure someone wrote it before me. Do you know any good open source that does it?
I want the wrapper to organize the fai开发者_如何学JAVAlure string for example. So it would be uniform to search it on the logs.
Thanks!
p.s. is it a bad practice to use the JUnit on producation code?
Look into AspectJ (or other similar aspect-oriented products). You can simply include an annotation to the method to call one of your pointcuts to automatically check the inputs.
It is definitely bad to include JUnit in production code. There should be clear separation from your production code and your testing code. Can you explain what you're trying to do with it? You're not giving us a lot to go on.
To Kaj's point, if you want to return a list of errors, just return List if you want to do the message formatting in the called class, or List or List if you want to do the formatting in the calling class.
精彩评论