0

I have a Coded UI test on a simple calculator application in data driven mode. After adding an assertion, I am not getting my test result passed which I think is due to "." (the decimal point which is already present in Windows calculator application).

Hence I just want to know how to write code so that all type of values including decimal and integers are accepted. My CSV file used for the data-table is

input1     input2      expected_add
1.2         2.3        3.5
2.4         2.5        4.9
5.6         1.4         7    

Here the first and second rows are passing but third one is failing.

Here is the sample code that I used for data driven testing.

this.UIMap.add_2_dec_numParams.UICalculatorDialogSendKeys = TestContext.DataRow["input1"].ToString();
this.UIMap.add_2_dec_numParams.UIItemEditSendKeys = "{add}" + TestContext.DataRow["input2"].ToString() + "=";
this.UIMap.add_2_dec_num();
this.UIMap.add_asertExpectedValues.UIItemEditText = TestContext.DataRow["expected_add"].ToString()+" ";
this.UIMap.add_asert();

The first two rows are getting passed because they have decimals. In the expected result of third row I need to make the value 7 as 7. only then it will be accepted by calculator. That is the problem..

If I change the code to the following:

this.UIMap.add_asertExpectedValues.UIItemEditText = TestContext.DataRow["expected_add"].ToString()+"."+" ";

Then the third row will pass and the first two rows will fail. And error will show as expected <3.5 > actual<3.5. > and expected <4.9 > actual<4.9. > that is the problem.

AdrianHHH
  • 13,492
  • 16
  • 50
  • 87
nks
  • 61
  • 2
  • 12
  • If you get your data (which you say you successfully get into your program), what is the problem adding it, and outputting it? Show us some code if there's the error, but I don't see how adding two floats can cause problems. – Hidde May 18 '12 at 09:16
  • thanks for ur answers. here is the sample code that i used for datadriven testing. this.UIMap.add_2_dec_numParams.UICalculatorDialogSendKeys = TestContext.DataRow["input1"].ToString(); this.UIMap.add_2_dec_numParams.UIItemEditSendKeys = "{add}" + TestContext.DataRow["input2"].ToString() + "="; this.UIMap.add_2_dec_num(); this.UIMap.add_asertExpectedValues.UIItemEditText = TestContext.DataRow["expected_add"].ToString()+" "; this.UIMap.add_asert(); – nks May 18 '12 at 12:36
  • first two rows are getting passed because they have decimals.but in the expected result of third row i need to make the value 7 as 7. then only it will be accepted by calulator..that is the problem and if i am doing it this way this.UIMap.add_asertExpectedValues.UIItemEditText = TestContext.DataRow["expected_add"].ToString()+"."+" "; then third row will be passed and first two row will be failed na d eoor will show as expexted <3.5 > actual<3.5. > expected <4.9 > actual<4.9. > that is the problem.hope u get it this time – nks May 18 '12 at 12:36
  • The TestContext.DataRow will try to convert the values auto-magically you will need to convert to a known/consistent data type to use in comparing non strings. – stoj May 21 '12 at 12:49

1 Answers1

0

My guess is that the assertion used is comparing strings instead of converting to integers or doubles and then comparing. A string comparison of "7" and "7." is of course going to fail.

Move your assertion out of the UIMap. Then convert the text value of the textbox and data row to doubles before doing an Assert.AreEqual. Use the version that has delta if you want to avoid some false positives from doubles being floating point numbers...

stoj
  • 679
  • 1
  • 10
  • 18
  • the prob wud had solved if i will be able to write "7." in csv file but its not possible.i dnt think we can change textbox to string as it is a winedit item which is default string. – nks May 18 '12 at 12:44