Re: Re: Asserts using Comparable.compareTo() instead of equals() (for BigDecimal and others)
Kevin Cooney <[email protected]> Tue, 18 Mar 2014 09:02:31 -0700
| Newsgroups | gmane.comp.java.junit.user |
|---|---|
| Message-ID | <CAA3E+eVR-+kn+v+a-Szn_BhUuawsjk9c4dpvt-HF9=JAqTgXAQ@mail.gmail.com> |
On Mon, Mar 17, 2014 at 11:39 PM, <[email protected]> wrote: > > > Thank you for clarifying. To clear up my point, I wasn't saying that there > wasn't a way to to compare BigDecimals, I was saying that there isn't a way > to do it that ships with Junit. There are hamcrest Matchers that ship with > JUnit, and there are hamcrest Matchers that handle BigDecimal comparisons > well, but none of those ship with JUnit. > JUnit depends on Hamcrest, and there are a even some JUnit APIs that accept Hamcrest matcher (like ExpectedException). So in a sense there is a way to compare BigDecimals that ships with JUnit. It's my understanding that the JUnit team has decided not try to provide a fully complete assertion framework, and instead has focused on making a really good, extensible testing framework. Luckily, there are many really good, supported, open-source Java assertion frameworks (including Hamcrest, Fest, Truth) that filled in that void. When we had trouble coming up with a set of good Comparable assertion APIs, and realized that Hamcrest (which JUnit itself integrates with) had a good set of Comparable assertion APIs, we decided to not add APIs to JUnit. Maybe that was the wrong decision, but it seemed like a reasonable one at the time. Perhaps you can come up with a good, simple API to do this. Or perhaps we were trying to solve the wrong problem, and there's a simpler API that meets 90% of your use cases. Either way, if you have a good idea, please feel free to send us a pull request. Most of the changes to JUnit don't come from those of us who help maintain JUnit@GitHub; they come from users like you. We do welcome your ideas and contributions. I'm just trying to give my understanding of the reasons we made the decision we did. > Given how heavily BigDecimal is used, and how standard it is, I feel that > JUnit should ship with Matchers that can handle it. > I'm a bit confused as to what you are asking for here. Are you suggesting that JUnit should include it's own Hamcrest Matcher that works with BigDecimal? That we should provide our own assertion DSL? Or that we should simply have an API that can assert that two BigDecimal values are the same? -- Kevin