Search This Blog

February 8, 2013

C# Unit Test: Put Negative Number in Bracket


Currently I use VSTS 2010 to write some unit tests to get the data from Oracle 11g and then do UI automation. I need to validate the value between the site and Oracle DB. However, the challenge part is that the value from DB has 3 or 4 decimal points, but the UI always shows 2 decimal points for numbers and 1 decimal point for percentage.

For example, I need to get the value from Oracle DB and then use percentage to display the value. If the value is negative such as -0.5%, the value needs to show (0.5%). 


Here is what I do:

Get the value from Oracle DB: “-0.005”

Convert string to double: -0.005

Format it to Percentage: "-0.5%"

If the value contains "-" sign, use ( ) to do the string format and then remove "-"

Get the value from the site and then compare the data between DB and the site.





I validate the data successfully. One interesting part is that the data is always correct in DB, but sometimes the value has the rounding error on the UI. I don’t feel surprised. 

No comments: