스크립팅 언어로 테스트 작성

C++ 및 C#외에도 TAEF는 스크립팅 언어로 테스트 작성을 지원합니다.

Microsoft COM 스크립팅 인터페이스를 지원하는 모든 스크립팅 언어를 사용하여 스크립트 구성 요소를 만듭니다. 이러한 인터페이스를 지원하는 스크립트 언어에는 JScript, Microsoft VBScript(Visual Basic Scripting Edition), PERLScript, PScript, Ruby 및 Python이 포함됩니다.

스크립트 테스트 작성의 현재 제한 사항

Windows는 JScript 및 VBScript만 지원합니다.

스크립트 테스트 파일 형식

스크립트 언어 테스트의 경우 TAEF는 약간 수정된 Windows 스크립트 구성 요소 파일 형식을 사용합니다. 다음 예제에서는 VBScript 및 JScript 테스트 클래스가 포함된 테스트 파일을 보여 줍니다.

1   <?xml version="1.0" ?>
2
3   <!-- Debugging helpers -->
4   <!-- error    Set this to true to display detailed error messages for syntax or run-time errors in the script component.-->
5   <!-- debug    Set this to true to enable debugging. If this debugging is not enabled, you cannot launch the script debugger for a script -->
6   <?component error="true" debug="true"?>
7
8   <package>
9       <!-- Test module metadata -->
10      <ModuleProperty name="Owner" value="Someone"/>
11
12      <!-- Define a test class -->
13      <component id="VBSampleTests">
14          <!-- define and instantiate a logger -->
15          <object id="Log" progid="WEX.Logger.Log" />
16  
17          <!-- include a reference to the logger so you could use the constants defined in logger library -->
18          <reference guid="e65ef678-a232-42a7-8a36-63108d719f31" version="1.0"/>
19
20          <!-- Test class metadata -->
21          <TestClassProperty name="DocumentationUrl" value="http://shelltestkb/"/>
22
23          <public>
24              <!-- Define a test method with metadata -->
25              <method name="TestOne">
26                  <!-- Test method metadata -->
27                  <TestMethodProperty name="Priority" value="1"/>
28              </method>
29  
30              <!-- Define a test method without metadata -->
31              <method name="TestTwo"/>
32         </public>
33
34          <script language="VBScript">
35              <![CDATA[
36                  Function TestOne()
37                      Log.Comment("Calling TestOne")
38                  End Function
39
40                  Function TestTwo()
41                      Log.Comment("Calling TestTwo")
42                  End Function
43              ]] >
44          </script>
45      </component>
46
47      <!-- Define another test class -->
48      <component id="JScriptSampleTests">
49          <object id="Log" progid="WEX.Logger.Log" />
50
51          <!-- need reference to use logger constants -->
52          <reference guid="e65ef678-a232-42a7-8a36-63108d719f31" version="1.0"/>
53
54          <public>
55              <!-- Test setup and cleanup methods are declared using corresponding type = '' attributes -->
56              <method name="ClassSetup" type="TestClassSetup"/>
57              <method name="ClassCleanup" type="TestClassCleanup"/>
58              <method name="MethodSetup"  type="TestMethodSetup"/>
59              <method name="MethodCleanup" type="TestMethodCleanup"/>
60
61              <method name="TestOne"/>
62              <method name="TestTwo"/>
63          </public>
64
65          <!-- Setup and Cleanup methods return false on failure -->
66          <script language="JScript">
67              <![CDATA[
68                  function ClassSetup()
69                  {
70                      Log.Comment("Calling class setup");
71                      return true;
72                  }
73
74                  function ClassCleanup()
75                  {
76                      Log.Comment("Calling class cleanup");
77                      return true;
78                  }
79
80                  function MethodSetup()
81                  {
82                      Log.Comment("Calling method setup");
83                      return true;
84                  }
85
86                  function MethodCleanup()
87                  {
88                      Log.Comment("Calling method cleanup");
89                      return true;
90                  }
91
92                  function TestOne()
93                  {
94                      Log.Comment("Calling TestOne");
95  
96                      // For the purpose of demonstration, declare the test failed
97                      Log.Result(TestResult_Failed);
98                  }
99
100                 function TestTwo()
101                 {
102                     Log.Comment("Calling TestTwo");
103                 }
104             ]] >
105         </script>
106     </component>
107 </package>

이 예제는 XML 파일이며 일반 XML 헤더로 시작합니다.

<?xml version="1.0" ?>

특성 오류 및 디버그를 설정하여 파일에 대한 디버그 설정을 구성합니다.

<?component error="true" debug="true"?>
  • 스크립트 구성 요소에 구문 또는 런타임 오류에 대한 자세한 오류 메시지를 표시하려면 오류를true 로 설정합니다.
  • 디버깅을 사용하도록 설정하려면 디버그를 true로 설정합니다. 디버깅을 사용하도록 설정하지 않으면 스크립트에 대한 스크립트 디버거를 시작할 수 없습니다(예: JScript 코드 내의 디버그 키워드(keyword)).

<패키지> 요소는 .wsc 파일에 테스트 클래스 정의를 묶습니다. 이 요소 뒤에 ModuleProperty 요소를 추가하여 모듈 수준 메타데이터를 삽입할 수 있습니다.

<ModuleProperty name = "Owner" value = "Someone"/>

ModuleProperty 요소에는 이름 특성이 포함되어야 합니다.

Component 요소는 스크립트 테스트 클래스에 대한 선언을 시작합니다. 이 요소에는 항상 클래스 이름으로 설정된 ID 특성이 있어야 합니다.

Component 요소 뒤에 TestClassProperty 요소를 사용하여 클래스 수준 메타데이터를 삽입할 수 있습니다. ModuleProperty 요소와 마찬가지로 이름 특성이 있어야 합니다.

이 시점에서 개체를 만들고 개체에 대한 참조를 정의할 수도 있습니다. 자세한 내용은 기타 구성 요소 섹션 을 참조하세요. XML 예제의 줄 15, 18, 49 및 52는 WEX를 참조하고 초기화하는 방법을 보여 줍니다 . Logger.Log 개체입니다.

<public> 요소는 테스트 스크립트 모듈의 테스트 메서드 선언을 묶습니다. 메서드 요소의 이름 특성에 테스트 메서드 이름을 지정하여 테스트 메서드>를< 선언합니다. 메서드 요소 내에<> 테스트 메서드 속성을 추가할 수도 있습니다. 다른 수준의 속성과 마찬가지로 필수는 아닙니다. 그러나 추가하는 경우 이름 특성을 포함해야 합니다.

<스크립트> 요소는 테스트 스크립트 언어를 식별하고 테스트 메서드의 구현을 묶습니다.

!<[ CDATA[]]> 섹션에는 스크립팅 언어로 작성된 코드인 테스트의 실제 구현이 포함되어 있습니다. 이 섹션에서는 public></public> 섹션에서 선언한 테스트 메서드를< 구현합니다.