Reputation: 468
I want to make UI automated test cases for system using Coded UI Test . and the test case have long life cycle, like:
when I playback this test case it doesn't work correctly because the system have saved this farm [ RMH-22 ] in the data base during recording.
Taking in consideration that the system saves unique code for farms.
Is there any solution to automate such test cases without deleting the database records manually before playback test cases?
Upvotes: 0
Views: 178
Reputation: 14076
The problem, as I understand it, is that the test is recorded using fixed names for farm and house, so those names are entered into the database. When the test is run again those same names are used but they are already in the database.
One approach is to ensure different names are used in each test run. I suggest creating a farm name and house names that include the date and time of the test run. So create names such as FarmYYYYMMDDHHMMSS
, H1YYYYMMDDHHMMSS
and H2YYYYMMDDHHMMSS
. If needed it would be easy to compress the date and time to make a shorter name. Generate the names in the code and then write values into fields of the ...Params
classes, much like is done in a data driven Coded UI tests.
As an alternative, some people suggest appending serial numbers (or letters), but that would mean keeping track of which number have already been used. Hence I would avoid that approach.
Update about compression of names.
If the project and the need for testing is short lived then parts or all of the year might be omitted. If you can guarantee that testing will not be needed after 2020 then just keep the year of the decade (currently '3'). Rather than YYMM
you could use day of the year, three digits in the range 1 to 366. You could encode the date as number of days since some start date; the number need not be precisely correct, just easy to calculate and giving suitable non-overlapping values. Eg (year - 2013) * 366 + day_of_year
Rather than HHMMSS
you could use second of the day, in the range 0 to 60*60*24 , ie 0 to 86400. Rather than using decimal digits for the name you could use a base 36 (see http://en.wikipedia.org/wiki/Base_36 ) encoding. Taken together these should better than halve the number of characters required for a date-time part of the name.
Upvotes: 2
Reputation: 1
I had this same situation occur in a CodedUITest system I built for a healthcare software product I work on. Basically it would throw off an exception after the first test successfully completed and the second one was starting up, and all the rest would end up failing as well.
Kept talking about a threading issue when it ended up being memory. It would end up building a large and complex database by the end of the test that I wished I could use again but because of how these tests work you will have to just wipe the entire database, and not only that but force a garbage collection on the entire map and its contents by setting all values to null to flag for collection and then forcing the collection to take place.
It sucks, I know trust me, but in a case like this it's better to just wipe the whole thing and rebuild all the data you have gathered every single test.
Upvotes: 0