【发布时间】:2016-05-24 09:47:56
【问题描述】:
我们有一个带有相应 JUnit 测试套件的 Java 项目,我们打算在 Linux 平台上运行它。它是使用 Windows 开发的,没有任何问题。
在 Linux 上使用 gradle test 运行我们的单元测试套件时,浮点差异开始出现。 IntelliJ 测试运行程序和 Gradle 内置运行程序之间似乎也存在差异。
使用的JDK:Sun JDK 1.8u91 x64
Running tests using 'gradle test' on Linux: ERRORS (see below)
Running tests using IntelliJ test runner on Linux: OK
Running tests using 'gradle test' on Windows: OK
Running tests using IntelliJ test runner on Windows: OK
junit.framework.AssertionFailedError: expected:<-2.18> but was:<-2.1652631074322057>
junit.framework.AssertionFailedError: expected:<1.11> but was:<1.1376954128942385>
junit.framework.AssertionFailedError: expected:<373.32> but was:<375.4870142751794>
【问题讨论】:
-
你能给出一个被测代码的示例代码sn-p吗?如果你想避免浮点问题,我建议你使用
java.math.BigDecimal
标签: java intellij-idea gradle junit