2

I am a new bee to Automation and Java. I am working on a problem which requires me to read the read time stock market data from the database and verify it with the same with the value seen on the UI. I am ok having approximations up to 5% in the value. To verify if these tests have passed its important for me to assert the values with the value in the UI.

I have a small logic to verify these values, I wanted to know if this is a good way of coding on java or do i have a better way to achieve these results.

Alorigthm.

  1. I read the int/float value from db.
  2. Calculate 5% of the value in step 1.
  3. Get the value in the UI and assert if its greater then or equal to value in step 2.
  4. If greater i say Asseert.assertEquals(true,true) else i fail my assert.

If any better way to work for these values, request a better answer.

1 Answers1

0

It's more usual to have your Assertion represent the meaning of your test, having to assert(true, true) does not do this. So:

 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)

Also you could consider using the Hamcrest extension to JUnit that includes a closeTo() method.

djna
  • 54,992
  • 14
  • 74
  • 117
  • hi djna thanks i was looking for an option with testng since these is an Assert.assertThat option in junt. Found a work around in http://www.jroller.com/alexRuiz/entry/fest_assert_another_assertthat_library – Krishna Jayanth Aug 19 '14 at 06:34