tcm: Importing Automated Tests into Test Cases
You can import automated tests, such as unit tests or coded UI tests, into your test project to use as part of a test plan. The tests are imported from a test assembly using the following tcm command:
- tcm testcase /import
Each automated test that you select, based on the parameters provided, has a test case created for it. The automated test is automatically associated with that test case. You can add test cases to a static test suite by using this command, or you can add test cases to test suites after you have imported them. For more information about how to add test cases to test suites, see Plan your tests. You can also link these test cases to requirements, so that you can view the status of automated tests for the requirement. For more information about how to do this, see Link Existing Test Cases to a Requirement.
For more information about how to run automated tests from a test plan, see Automate system tests.
tcm.exe is located in <Drive:>\Program Files\Microsoft Visual Studio <version>\Common7\IDE on any machine that has Visual Studio Enterprise or Visual Studio Test Professional.
You can also update existing imported test cases by using this command. If the test cases that you selected to update do not include tests that were previously imported, only the selected test cases are updated. If you specify a test suite to synchronize with when you update the test cases, the tests that are not imported are removed from the test suite but not the test plan itself.
tcm testcase /import /collection:CollectionURL /teamproject:project /storage:path [/maxpriority:priority] [/minpriority:priority] [/category:filter] [/syncsuite:id [/include:]] [/login:username,[password]]
||Specifies the URI of the team project collection. The format for the URI is as follows: http://ServerName:Port/VirtualDirectoryName/CollectionName
If no virtual directory is used, then the format for the URI is as follows:
||The name of the team project that contains the test plan that you want to import your automated tests into.|
||Specifies the path and name of the test assembly that contains your automated tests that you want to import.|
||Optional. Specifies which tests to import based on the maximum priority of the test method. For example, if the parameter is /maxpriority:1, only tests with a priority attribute for the test method less than or equal to 1 are imported as test cases from the assembly.|
||Optional. Specifies which tests to import based on the minimum priority of the test method. For example, if the parameter is /minpriority:2, only tests with a priority attribute for the test method equal or greater than 2 are imported as test cases from the assembly.|
||Optional. Specifies which tests to import based on the category of each test method in the test assembly. You can use this parameter together with /syncsuite to import tests with a certain category into a specific test suite.
For more information about test categories see Defining Test Categories to Group Your Tests.
||Optional. Specifies the suite ID for the test suite in your test plan to which you want to add the test cases that you import. This suite cannot be a dynamic suite or a query-based suite. If you specify a test suite to synchronize to update tests that have already been added, the tests that are not imported are removed from the test suite but not from the test plan itself.
To determine the suite id for the test suite that you want to use, you can use the following command to list the test suites in your team project:
tcm suites /list
For more information about this command, see tcm: Listing test plans, test suites, test configurations, and environments.
|/include||Optional. Specifies that test methods that are marked with an Ignore() attribute are also imported.|
||Optional. Specifies the name and password of a user who is logged on to the application-tier server for Team Foundation Server and who has permissions to run the command. You would use this option if your Windows credentials do not have the appropriate permissions, or you are using basic authentication, or you are not connected to a domain.
To login to Visual Studio Team Services, you will also need to use /allowalternatecredentials listed below.
|/allowalternatecredentials||This flag must be specified in addition to the /login parameter when connecting to Visual Studio Team Services. (This flag is only available if you have Visual Studio 2013 Update 4 or greater.)|
You can add parameters for /collection and /teamproject to the tcm.exe.config XML file which is located in the same directory as tcm.exe: <Drive:>\Program Files\Microsoft Visual Studio 11.0\Common7\IDE. If you add these to the file, you do not have to enter them on the command line each time you run a tcm command. You can add these keys and their values to the file, as follows, in the appSettings section:
<appSettings> <add key="TeamFoundationServer" value="https://<ServerName:Port/VirtualDirectoryName/CollectionName>"/> <add key ="TeamProject" value="DinnerNow"/> </appSettings>
Import Test Cases
The following examples assume that you have started a Visual Studio command prompt. (Go to Start, All Programs, Microsoft Visual Studio, Visual Studio Tools, Developer Command Prompt.)
The command prompt opens to the folder: <drive>:\Program Files\Microsoft Visual Studio 11.0\VC
Change directory to the folder that contains the assembly built from your test project.
The following command imports tests from the TestProject1.dll into the DinnerNow team project:
tcm testcase /import /collection:https://<Team Foundation Server Name>:8080/tfs/<team project collection name> /teamproject:DinnerNow /storage:TestProject1.dll
The following command imports only the test cases with a priority of 1:
tcm testcase /import /collection:https://<Team Foundation Server Name>:8080/tfs/<team project collection name> /teamproject:DinnerNow /storage:TestProject1.dll /maxpriority:1
The following command imports only the test cases in the SmokeTest and ShoppingCart categories and adds them to the test suite with id of 3:
tcm testcase /import /collection:https://<Team Foundation Server Name>:8080/tfs/<team project collection name> /teamproject:DinnerNow /storage:TestProject1.dll /category:"ShoppingCart&SmokeTest" /syncsuite:3