MSDN Magazine Launch Issue - February 15, 2008 - (Page 29) In this simple example, I have three test cases. The first test of the TriMax(x,y,z) method has an ID of 001, inputs of 3, 5, and 7, and an expected result of 7. The second test case has a deliberate failure for demonstration purposes. Notice that I initialize a variable named allPassed to true. This variable tracks whether or not all the individual test cases pass. My test automation iterates through each test case, parsing out the test case ID, the inputs, and the expected value. With those values in hand, my script invokes the method under test and compares the actual result with the expected result to determine a pass/fail result for the individual test case: var actual = o.TriMax(arg1,arg2,arg3); if (actual == expected) { WScript.Echo(“Pass”); } else { WScript.Echo(“**FAIL**”); allPassed = false; } If I find any failing test case, I set the value of the allPassed variable to false. Finally, my example test script finishes by using the WScript.Quit method to set the process exit code to 0 or 1: if (allPassed == true) { WScript.Echo(“\nAll test cases passed”); WScript.Quit(0); } else { WScript.Echo(“\nOne or more cases failed”); WScript.Quit(1); } If you intend to manage simple custom test automation with VSTE for Testers, your automation must set an exit code of 0 to indicate that the overall test result is pass or an exit code of 1 to indicate failure. This means that if you are going to integrate existing test automation with VSTS, you will likely have to edit your automation because test automation rarely sets the exit code value. Exactly how you set the exit code varies slightly from language to language. For example, in a .NET-compliant language program, you can use the System.Environment.ExitCode property, and in a Windows PowerShell script, you can use the exit statement. At this point you can execute the test automation script locally, as shown in Figure 1. But you can also run custom automation from within VSTE for Testers. Select File | New | Project. The New Project dialog has a Test Projects type with a Test Documents subtype. Select Test Documents and you will see a Test Project template. Next, give the test project a name such as MyTestProject and specify a location for the project root directory. A Test Project can hold one or more tests. Each test can hold one or more individual test cases. By default, you will get a Test Project that contains a general help text document named AuthoringTests.txt and the skeletons for two tests: a manual test and a unit test. You can delete these three files in the Solution Explorer window. Now right-click on your Test Project name and select Add | New Test from the context menu. In the Add New Test dialog box, select the Generic Test template, name it Simple.GenericTest, and then Test Run launch2008 29 http://www.iocomp.com http://www.iocomp.com
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.