【问题标题】:Differences between IntelliJ JUnit test runner and Gradle JUnit test runner on LinuxLinux 上 IntelliJ JUnit 测试运行器和 Gradle JUnit 测试运行器之间的差异
【发布时间】: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


【解决方案1】:

关键部分是:

final double amountInEUR = (amountInOtherCurrency - (quantity * commission)) * (closePrice * closePriceMultiplier);

如您所见,它是一个财务应用程序。对 BigDecimal 的一些研究确实表明这是要走的路。谢谢兰斯 Java!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    • 1970-01-01
    • 2011-04-03
    • 2015-09-26
    相关资源
    最近更新 更多