You can create coded UI tests in VS to record software operations, replay them, and finally run independently from vs.
Run the test in VS
Create a project codeuitest, control layout, such as:
Add code under the button click event:
if (string. IsNullOrEmpty (This.textBox1.Text)) { MessageBox.Show ("Please enter your name!") ");} else{ MessageBox.Show (string. Format ("Hello \" {0}\ "!", This.textBox1.Text));}
Under test, click the Create Test menu, select the Coded UI test template, and set the project name. (compared with VS2013, really like VS2010 this method of creating test projects)
Choose to generate the UI encoding by recording.
Recording
When the VS icon appears on the target form, you can start the action
Stop recording and generate code
You can see the test status in the test results view
Run the UI test independently from VS
Create the project Codeuitestexe and join the Codeuitest solution. As follows:
Add to Microsoft.VisualStudio.QualityTools.UnitTestFramework, Microsoft.VisualStudio.TestTools.UITest.Common, Microsoft.VisualStudio.TestTools.UITest.Extension, Microsoft.VisualStudio.TestTools.UITesting and Codeuitest, A reference to the TestProject1 project.
The CodeUITestExe.Form1.cs code is as follows:
Using testproject1;namespace codeuitestexe{public partial class Form1:form {public Form1 () { InitializeComponent (); } private void Button1_Click (object sender, EventArgs e) { TestProject1.TestInit.Init (); Testproject1.codeduitest1 test = new Testproject1.codeduitest1 (); Test. CodedUITestMethod1 (); TestProject1.TestInit.Cleanup ();}}}
Create the class TestInit.cs in TestProject1 with the following code:
Using Microsoft.visualstudio.testtools.uitesting;namespace testproject1{public class Testinit { public static void Init () { if (! playback.isinitialized) { playback.initialize (); } } public static void Cleanup () { if (playback.isinitialized) { playback.cleanup () }}}}
Compile the solution, open CodeUITest.exe, and then open CodeUITestExe.exe, and when you do the test, you can C:\Program Files\Microsoft Visual Studio 10.0\ when the DLL is not found The DLL under Common7\IDE\PrivateAssemblies is copied to debug under the Microsoft.VisualStudio.TestTools.UITest prefix.
When you copy the program code to another computer, you will be prompted to "cannot perform" on the control error when you perform the test, and continue to find the error "CLSID {6DA215C2-D80D-42F2-A514-B44A16DCBAAA} Failed due to the following error:80040154 Class no registered (Exception from hresult:0x80040154 (Regdb_e_classnotreg) ).”。 The reason is that the Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.dll file is missing. Copy this file under C:\Program Files\Common Files\Microsoft shared\vstt\10.0 to debug and register through Regsvr32, making sure that you open a command prompt as an administrator to perform the registration.
Demo instance source, click to download
Codedui Automated testing and disengagement vs standalone operation