Summary:
1: Test requirements
2: Run automated testing in
3: Automated Testing Without
In the previous article "C # using API to achieve the compilation of Black Box automated testing tools" (http://www.cnblogs.com/luminji/archive/2010/11/03/1867730.html), we use windows api to achieve the compilation of automated testing tools. However, this method requires meticulous and complex work during large-scale software testing. After VS2010, let's take a look at Code UI Automation. Code UI Automation has been introduced many times. The focus of this article is as follows:
1. Use Code UI Automation to record manual UI operations so that VS can automatically generate test Code based on these operations;
2: Create a WINFORM Project (that is, the Black Box tool) and call the automatically generated code in this WINFORM project;
As mentioned above, the reason for VS to automatically generate code is to avoid the complicated work of writing test code manually. The 2 mentioned above aims to remove our test tool from.
Download this article: http://download.csdn.net/source/2839416
I. test requirements
The test requirements are as follows:
1: provides a WINFORM with a TextBox and a Button;
2: click the Button. A prompt box is displayed. The prompt box contains the TextBox value;
Now, the test requirements are as follows:
1: run the above program on 300 machines;
2: Go to the 300 machines and click the Button to see if function 2 has been implemented;
2. Run automated testing in
To illustrate this example, we created the solution WindowsFormsApplicationTest, which is divided into three projects:
- WindowsFormsToBeTest: The tested application;
- TestProject1, VS2010 test project (using. NET FRAMEWORK4 );
- WindowsFormsTester, the Black Box tool to be compiled, is also a WINFORM;
Assume that WindowsFormsToBeTest has been compiled and runs. Now we use Code UI Automation (New "coded UI test") in TestProject1 to record operations (the operation procedure is: Enter "ABC" in the text box of WindowsFormsToBeTest, and click "Button" to bring up the prompt, click OK), and then generate the Code, such:
Find the public test method in the generated code:
[TestMethod]
Public void CodedUITestMethod1 ()
{
This. UIMap. RecordedMethod1 ();
}
In fact, by viewing this. UIMap. RecordedMethod1 (), VS also calls the windows api to obtain the handles of various controls. At this time, if we run the selected test CASE in the VS test List editor,
We will find that VS automatically replays a complete recording operation for us. As follows:
Iii. Run automated tests without
The next task is to run this test in our own application WindowsFormsTester.
3.1: first, we need to reference these DLL in WindowsFormsTester:
They should be in a folder similar to the following, D: Program FilesMicrosoft Visual Studio 10.0Common7IDEPrivateAssemblies. If you do not reference these files, the compilation will pass, but the following error will be reported during the runtime: failed to load the file or assembly "Microsoft. visual Studio. testTools. UITest. extension. IE. communication. interop, Version = 9.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a "or one of its dependencies. The system cannot find the specified file.
3.2: provide a class in TestProject1 to provide a static method, as follows:
Public class TestInit
{
Public static void Init ()
{
Playback. Initialize ();
}
}
Note that Playback. Initialize () must be run. Otherwise, all the handles obtained by your application are invalid.
3.3: Now, you can call the public method in TestProject1 in WindowsFormsTester, as follows:
TestInit. Init ();
CodedUITest1 c = new CodedUITest1 ();
C. CodedUITestMethod1 ();
In this way, we have completed a Black Box automated testing tool WindowsFormsTester that is out of.
With the automatic generation of Code UI Automation, the complicated and meticulous test Code compilation work is handed over to VS's test engine for implementation, we can put more details on the business logic of the test, rather than trying to get the handles of various controls and operate on them.
Special thanksZhou JingshengHttp://hi.csdn.net/space-1424875.html?help.