开发者

How to copy a Visual Studio database unit test

开发者 https://www.devze.com 2023-01-07 17:46 出处:网络
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

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").

  1. In Solution Explorer, copy-paste the unit test file. Rename the new file.
  2. Right-click the new file and select View Code to open the C#/VB code file.
  3. 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".
  4. 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.
  5. Perform the same Replace All in this file.
  6. Save all, then re-open the test in the designer and your new test is ready to go.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号