Run the Visual Studio test code using scripts

Source: Internet
Author: User

I wrote an article about how to use Visual Studio for white-box testing. Please refer to my previous article:

Getting started with Visual Studio white box testing

It has problems. It generates *. the TRX result file records the result information and log information of the running test method. If we write a large number of logs to the TRX file, the TRX file cannot be saved to the hard disk. I have tried it. As long as the TRX file seems to be the maximum, it will not exceed 10 MB.

However, our project must use the TRX file to analyze the TRX file to automatically send the log result to the database, which indicates that a test was run. I can't always run a few test methods every time, so I have to wait in front of the computer, constantly select the test method for execution, wait for the execution to complete, and then repeat the test method selection and execution .....
The crash does not reflect the advantages of automated testing.
Well, after research, do you have a way to make the machine automatically execute the task? So I have to find the method.
There will be an mstest.exe program under the vsinstallation directory. For example, on my machine, the program is located at: C:/program files/Microsoft Visual Studio 8/common7/IDE/mstest.exe
With this program, we can run testmethod without starting Visual Studio.

Let's take a look at the help of mstest ,:

 

Msdn: mstest.exe command-line options

 

In our vs test project directory, there will be a file named *. vsmdi, which is an XML file that describes the test method and its structural relationship of the project. Copy the file to the output directory of the test project, which is associated with the DLL generated by the test project. Then execute the following command in the command line

C:/program files/Microsoft Visual Studio 8/common7/IDE/mstest.exe/testmetadata: testproject1.vsmdi/test: testmethod1/test: testmethod2

 

After a while, we can see that two test methods have been executed. Similarly, if you want to execute other test methods, add/test after the command line: The test method name is OK.

 

However, this method is inconvenient. If we have thousands of testmethods, do we need to add them one by one? Tired and exhausted. In this case, the new test list we added takes effect. Run the following command:

C:/program files/Microsoft Visual Studio 8/common7/IDE/mstest.exe/testmetadata: testproject1.vsmdi/testlist: math

In this way, all testmethods of math can be run.

 

Another method is to run test method based on DLL:
"C:/program files/Microsoft Visual Studio 8/common7/IDE/mstest.exe"/resultsfile: C:/tesresult. Trx/testcontainer: C:/testproject1.dll/test: testmethod1/unique

 

With this command line method, we can write it as a bat script file. Imagine that if our tests are more standardized, We can automatically build code after work every day during development, and then run the test project automatically, the next morning, you will be able to know the general situation of daily build. Or, before releasing a version, use the program to automatically test whether there is any obvious bug, and then submit it to the tester for testing.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.