Search code examples
javatestingboundary

Boundary Case Testing in Java


Are there any tools for JUnit or Java practises that allow for boundary case tests like "less than" and "greater than" to be accurately tested?

For example, rounding monetary values half-up to nearest cent. Testing 0.005 rounds up to 0.01 is easy. Testing <0.005 rounds down is not (strictly speaking).

I can obviously test an arbitrary value like 0.0049, but this doesn't guarantee that another value like 0.00499 doesn't get rounded up. Is there a constant or whatever that guarantees the numerical value that is the closest possible representation to "less than" or "greater than" for the environment being executed on?


Solution

  • Probably but this depends on many factors. For monetary values, you should always use BigDecimal since it gives you complete control over the precision (like double or float which can give odd results even for simple values)