使用java自动化实时数据

时间:2014-08-19 05:13:06

标签: java junit automation testng

我是自动化和Java的新宠。我正在研究一个问题,这个问题要求我从数据库中读取读取时间股票市场数据,并使用与UI上看到的值相同的方式对其进行验证。我可以接近最高5%的值。要验证这些测试是否已经过了重要的事情,我必须使用UI中的值声明值。

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

Alorigthm。

  1. 我从db。
  2. 读取了int / float值
  3. 计算步骤1中值的5%。
  4. 获取UI中的值并断言其是否大于或等于步骤2中的值。
  5. 如果更大,我说Asseert.assertEquals(true,true),否则我的断言失败。
  6. 如果有更好的方法来处理这些值,请求更好的答案。

1 个答案:

答案 0 :(得分:0)

让Assertion代表测试的意义更常见,不得不断言(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扩展。