Walkthrough: Creating and Running a Generic Test
This walkthrough will step you through the process of wrapping an executable file as a generic test, then running the test. You will start by creating an executable file using existing sample code. Next, you will create a new generic test and add the executable file to the generic test. Finally, you will run the test.
For information about generic tests, see Generic Tests Overview.
In this walkthrough, you will complete the following procedures:
Create a program, that is, an executable file, to wrap as a generic test. This program represents a third-party testing tool that produces pass or fail results for its exit or return value at program completion. See Prepare the Walkthrough.
Create the generic test.
Run the generic test.
Pass command-line arguments when you run the generic test. For more information, see Run the generic test.
Deploy a File When You Run the Generic Test.
You must create the executable file EvenOdd.exe. To do this, use the source code in Generic Test Sample and follow the steps in the next procedure, "Prepare the Walkthrough."
Prepare the Walkthrough
To prepare the walkthrough
Create a project for a new Visual C# console application. In Name field of the New Project dialog box, type EvenOdd and then click OK.
The EvenOdd solution is displayed in Solution Explorer. It contains a project named EvenOdd.
Within the EvenOdd project, open the source-code file Program.cs.
Replace the code of the Program.cs file with the code in Generic Test Sample.
Build the solution.
This creates the program that you will wrap to create a generic test.
Create a Generic Test
To create a generic test
Right-click the EvenOdd solution, point to Add, and then click New Project.
The AddNew Project dialog box is displayed.
In the Add New Project dialog box, expand Visual C# and then click Test.
In the Templates pane, click Test Project and then click OK. Accept the default name, for example, TestProject1.
Right-click the test project, point to Add, and then click Generic Test.
The template for a generic test is added to your test project and appears in the main editing window. The new generic test is given a default name, such as GenericTest1.GenericTest, and is displayed in Solution Explorer.
Under Specify an existing program (a test, test harness, or test adapter) to wrap as a generic test, indicate the path and file name of the EvenOdd.exe file.
To determine this path, click Options on the Tools menu and then click Projects and Solutions. The path of the EvenOdd solution is displayed under Visual Studio projects location. The EvenOdd solution contains a folder for the EvenOdd project. Under the EvenOdd project folder, EvenOdd.exe resides under bin\Debug\.
This designation will look similar to the following sample:
D:\Documents and Settings\<your user name>\My Documents\ 2005\Projects\EvenOdd\EvenOdd\bin\Debug\EvenOdd.exe.
Save the generic test.
You have created a generic test that wraps EvenOdd.exe. This test has the following characteristics:
You can run the test from a command line.
The test returns a value of 0, for Passed, or 1, for Failed.
You can now run the generic test from the Test View window or Test List Editor. To run the test now, see Run the Generic Test.
Run the Generic Test
To run the generic test that you created
Open the Test View window.
Click the generic test.
Click Run Selection in the Test View toolbar.
The EvenOdd executable file returns a value of 0 or 1 at random. Accordingly, when the generic test that wraps EvenOdd runs, it passes or fails depending on the number generated by EvenOdd. The Test Results window displays the result, either Passed or Failed.
In general, a generic test passes when the executable it wraps returns a value of 0, and fails if any other value is returned.
You can also pass arguments to the EvenOdd executable file. A test based on EvenOdd.exe passes or fails depending on the supplied arguments. For a description of the values that EvenOdd.exe returns, see Generic Test Sample.
To pass an argument when you run the generic test, on the GenericTest1.generic page, type 12 on the line Command line arguments to pass to the generic test and run the test again.
Because you passed an even number, the test passes. You can confirm this result in the Test Results window.
(Optional) Run the test additional times, passing in different values.
Some existing tests or executable programs require additional files when they run. You can specify files to deploy along with a generic test. For more information, see Deploy a File When You Run the Generic Test.
Deploy a File When You Run the Generic Test
To deploy an additional file when you run the generic test
Create and save a file that is named mydeployedfile.txt. The file can be empty. Note the folder in which you created it.
Under Additional files to deploy with this generic test, click Add.
The Add Deployment Files dialog box is displayed.
In the Add Deployment Files dialog box, under Files of type, click All files(*.*).
Navigate to the folder that contains mydeployedfile.txt, select the file, and then click Open.
You have specified mydeployedfile.txt to be deployed when you run the generic test.
In the following steps, you can verify that the file is being deployed. You do this by using a specific feature of EvenOdd.exe that produces a Passed or Failed result depending on the presence or absence of the file that you specified.
In the generic test, change the value of the Command-line arguments to pass to the generic test run setting to: 12 "%TestDeploymentDir%\mydeployedfile.txt"
Save the generic test.
Two command-line arguments are now passed to the generic test. This change causes EvenOdd.exe to use a different criterion to produce a result of Pass or Fail. When you pass two arguments, the first argument is ignored. If the file specified by the second argument exists in the same directory as the test, the test passes. However, if the file was not deployed or if the name of the file specified in the command-line argument does not match the name of the deployed file, the test fails.
To run the test now, see Run the Generic Test.