I'm writing unit tests for stored procedures in VSTE for Database Professionals, and want to copy some already existing test cases that only need to be modified in a few places. Manually re-creating them would be very tedious. I couldn't find a solution either on 开发者_运维百科the web or in books. Any ideas are welcome.
It's definitely not easy but here is the best method that I've found.
This method assumes that each test file contains 1 or more tests targeting the same database object. (Ex: PeopleTest.cs runs tests against the People table; spGetPeopleTest.cs targets stored procedure spGetPeople...) This makes the replace-all easier (for example you'd copy a PeopleTest.cs file and rename all "People" references to "Tasks").
- In Solution Explorer, copy-paste the unit test file. Rename the new file.
- Right-click the new file and select View Code to open the C#/VB code file.
- Perform a Replace All in the code file. For example if the original test referenced a Tasks table and you want your new test to reference a People table, replace "Tasks" with "People".
- In Solution Explorer, expand the new test file to expose the .resx file. (This is where the SQL code is stored.) Right-click the .resx file, select Open With, then select XML Editor.
- Perform the same Replace All in this file.
- Save all, then re-open the test in the designer and your new test is ready to go.
精彩评论