locked
Architecting Coded UI Tests RRS feed

  • Question

  • I would like to set up automated testing using coded UI tests.  At first I was thinking I would like to record actions that a manual tester might do and then assert values on certain UI elements.  Some actions might require modification of database records (insert, update, delete).  For a simple example say i have a textbox and a button.  In the textbox i will input a customer name and then the button will add the customer to the database.  Next i will have an items control that displays a list of added customers.  So in my coded UI test I would like to input a customer name, push the button to add the customer to the database and then assert the customer is displayed in the items control.  There may be some issues with this approach though because say I have a method that checks for duplicate names and when i push the button to add the customer it shows a messagebox saying you can't add the a customer with the same name.  Running my coded UI test more than once may produce unexpected results because its trying to add the same data multiple times to the same database.  There are some possible solutions that i can think of to get around this issue.  1) Clean up my data modifications at the end of my test method.  2) Create a mock repository or a dedicated testing database that i can revert back to a database snapshot at the beginning of each test run  3) Don't worry about cleanup and append some random/unique id to the end of each field where duplicates may become an issue.  Any suggestions?

    Furthermore, i have an even bigger question about what the goal of coded UI testing should be?  Am I going about this wrong?  Should I not be trying to validate data in the UI that involves actions that interact with the database?  Should I instead be unit testing the api of my service layer (that gets called from the UI/ViewModel) using a mocking framework?

    Friday, March 13, 2015 2:41 PM

Answers

  • Hi nighttrain79,

    Thank you for posting in the MSDN forum.

    Actually the coded UI test is used to test your UI controls.

    >>So in my coded UI test I would like to input a customer name, push the button to add the customer to the database and then assert the customer is displayed in the items control

    >>There may be some issues with this approach though because say I have a method that checks for duplicate names and when i push the button to add the customer it shows a messagebox saying you can't add the a customer with the same name.

    As you said that when you input a name, but the name has been added in the database, so you would get the warning which said that "can't add the a customer with the same name". One impoartand issue is that the coded UI tests playback the actions recorded by the coded UI test builder. If you recorded the

    method which just used for the correct name, when you run it with the same name with the previous any one, your coded UI test would be failed. But the coded UI test is correct even if the result is failed.

    I have a suggestion which is that you could use the data driven test, and then use the database for the names inputed in your textbox, in your coded UI test method, please re-load the UI for every row in this database, so when you run your test with the custom database, other row which failed the test would not impact other row's result. After all tests finished, you could check which row has this wrong/failed result, and then change it in your side.

    Actually I mean that the coded UI test method is used to test the UI control. The test result is failed, it doesn't mean that your UI has any issue. Like your test, even if the test method failed with one row which have the same name as another row, but it doesn't mean your test method has certain issues.

    If I have misunderstood this issue, please feel free to let me know.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 16, 2015 7:47 AM

All replies

  • I would like to set up automated testing using coded UI tests.  At first I was thinking I would like to record actions that a manual tester might do and then assert values on certain UI elements.  Some actions might require modification of database records (insert, update, delete).  For a simple example say i have a textbox and a button.  In the textbox i will input a customer name and then the button will add the customer to the database.  Next i will have an items control that displays a list of added customers.  So in my coded UI test I would like to input a customer name, push the button to add the customer to the database and then assert the customer is displayed in the items control.  There may be some issues with this approach though because say I have a method that checks for duplicate names and when i push the button to add the customer it shows a messagebox saying you can't add the a customer with the same name.  Running my coded UI test more than once may produce unexpected results because its trying to add the same data multiple times to the same database.  There are some possible solutions that i can think of to get around this issue.  1) Clean up my data modifications at the end of my test method.  2) Create a mock repository or a dedicated testing database that i can revert back to a database snapshot at the beginning of each test run  3) Don't worry about cleanup and append some random/unique id to the end of each field where duplicates may become an issue.  Any suggestions?

    Furthermore, i have an even bigger question about what the goal of coded UI testing should be?  Am I going about this wrong?  Should I not be trying to validate data in the UI that involves actions that interact with the database?  Should I instead be unit testing the api of my service layer (that gets called from the UI/ViewModel) using a mocking framework?

    Friday, March 13, 2015 2:15 PM
  • Hi nighttrain79,

    Thank you for posting in the MSDN forum.

    Actually the coded UI test is used to test your UI controls.

    >>So in my coded UI test I would like to input a customer name, push the button to add the customer to the database and then assert the customer is displayed in the items control

    >>There may be some issues with this approach though because say I have a method that checks for duplicate names and when i push the button to add the customer it shows a messagebox saying you can't add the a customer with the same name.

    As you said that when you input a name, but the name has been added in the database, so you would get the warning which said that "can't add the a customer with the same name". One impoartand issue is that the coded UI tests playback the actions recorded by the coded UI test builder. If you recorded the

    method which just used for the correct name, when you run it with the same name with the previous any one, your coded UI test would be failed. But the coded UI test is correct even if the result is failed.

    I have a suggestion which is that you could use the data driven test, and then use the database for the names inputed in your textbox, in your coded UI test method, please re-load the UI for every row in this database, so when you run your test with the custom database, other row which failed the test would not impact other row's result. After all tests finished, you could check which row has this wrong/failed result, and then change it in your side.

    Actually I mean that the coded UI test method is used to test the UI control. The test result is failed, it doesn't mean that your UI has any issue. Like your test, even if the test method failed with one row which have the same name as another row, but it doesn't mean your test method has certain issues.

    If I have misunderstood this issue, please feel free to let me know.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 16, 2015 7:47 AM