gpt4 book ai didi

java - 使用java自动化实时数据

转载 作者:行者123 更新时间:2023-11-29 08:45:56 26 4
gpt4 key购买 nike

我是自动化和 Java 的新手。我正在处理一个问题,该问题需要我从数据库中读取读取时间的股市数据,并使用与 UI 上看到的值相同的值对其进行验证。我可以接受高达 5% 的近似值。为了验证这些测试是否已通过,对我来说很重要的是用 UI 中的值断言这些值。

我有一个小逻辑来验证这些值,我想知道这是否是一种在 Java 上编码的好方法,或者我是否有更好的方法来实现这些结果。

算法。

  1. 我从数据库中读取了 int/float 值。
  2. 计算第 1 步中值的 5%。
  3. 获取 UI 中的值并断言它是否大于或等于步骤 2 中的值。
  4. 如果更大,我说 Assert.assertEquals(true,true) 否则我的断言失败。

如果有任何更好的方法来处理这些值,请请求更好的答案。

最佳答案

更常见的做法是让你的断言代表你的测试的意义,而必须 assert(true, true) 不会这样做。所以:

 3. Calculate the absoluete difference between the value obtained in step 1 and the UI value (when I say absolute value, you need to remember that the UI might be higher or lower than the db value, you need to make the difference to be always positive)
4. Assert.assertThat( difference < theFivePercentValue)

您还可以考虑使用包含 closeTo() 方法的 JUnit 的 Hamcrest 扩展。

关于java - 使用java自动化实时数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25376045/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com