스크립팅 언어의 데이터 기반 테스트
이 섹션을 이해하려면 스크립팅 언어로 테스트를 작성하는 방법을 잘 알고 있어야 합니다. 이 섹션에서는 다양한 TAEF 데이터 기반 테스트 접근 방식에 대해 자세히 설명하지 않습니다. 빠른 개요는 다양한 TAEF 데이터 기반 테스트 구문을 검토합니다.
위의 데이터 원본 중 하나 이상의 데이터 원본을 사용하여 데이터 원본의 조합을 선택할 수도 있습니다. 자세한 내용은 여러 DataSources 지정 을 참조하세요.
스크립팅 언어로 데이터 원본 지정
TAEF의 데이터 기반 테스트를 사용하면 클래스 또는 테스트 수준에서 DataSource 를 지정할 수 있습니다. 데이터 기반 클래스에서는 클래스 및 테스트 메서드 설정, 정리 및 클래스의 모든 테스트 메서드에 데이터를 사용할 수 있습니다. DataSource 매개 변수는 데이터를 검색할 위치를 알려주는 정보입니다. 테이블 기반 데이터 기반 테스트의 경우 이 값에는 XML 파일에 대한 상대 경로와 데이터가 있는 XML 파일의 TableId가 포함됩니다. 자세한 내용은 위에 나열된 링크를 참조하세요.
다음 예제에서는 DataSource 속성을 지정하는 방법을 보여줍니다.
1 <?xml version="1.0" ?>
2 <?component error="true" debug="true"?>
3 <package>
4 <component id="VBSampleTests">
5 <object id="Log" progid="WEX.Logger.Log" />
6 <object id="TestData" progid="Te.Common.TestData" />
7
8 <public>
9 <method name="TestOne">
10 <TestMethodProperty name="DataSource" value="WMI:SELECT Label, Caption FROM Win32_Volume"/>
11 </method>
12
13 <method name="TestTwo">
14 <TestMethodProperty name="DataSource" value="Table:ScriptExampleTable.xml#MyTable;WMI:SELECT Label, Caption FROM Win32_Volume"/>
15 </method>
16 </public>
17
18 <script language="VBScript">
19 <![CDATA[
20 Function TestOne()
21 dim caption
22 caption = "NoCaption"
23 Log.Comment("Caption is " + caption)
24
25 If TestData.Contains("Caption") Then
26 caption = TestData.GetValue("Caption")
27 End If
28 Log.Comment("Caption is " + caption)
29 End Function
30
31 Function TestTwo()
32 Log.Comment("Calling TestTwo")
33 dim caption
34 caption = "NoCaption"
35 Log.Comment("Caption is " + caption)
36
37 If TestData.Contains("Caption") Then
38 caption = TestData.GetValue("Caption")
39 End If
40 Log.Comment("Caption is " + caption)
41
42 dim size
43 If TestData.Contains("Size") Then
44 size = TestData.GetValue("Size")
45 End If
46 Log.Comment("Size is " + CStr(size))
47
48 dim transparency
49 If TestData.Contains("Transparency") Then
50 transparency = TestData.GetValue("Transparency")
51 End If
52 Log.Comment("Transparency is " + CStr(transparency))
53 End Function
54 ]] >
55 </script>
56 </component>
57
58 <component id="JScriptSampleTests">
59 <object id="Log" progid="WEX.Logger.Log" />
60 <object id="TestData" progid="Te.Common.TestData" />
61
62 <TestClassProperty name="DataSource" value="Table:ScriptExampleTable.xml#MyTable"/>
63
64 <public>
65 <method name="ClassSetup" type="TestClassSetup"/>
66 <method name="ClassCleanup" type="TestClassCleanup"/>
67 <method name="MethodSetup" type="TestMethodSetup"/>
68 <method name="MethodCleanup" type="TestMethodCleanup"/>
69
70 <method name="TestOne"/>
71 <method name="TestTwo">
72 <TestMethodProperty name="DataSource" value="WMI:SELECT Label, Caption FROM Win32_Volume"/>
73 </method>
74 </public>
75
76 <script language="JScript">
77 <![CDATA[
78 function ClassSetup()
79 {
80 Log.Comment("Calling class setup");
81 var size;
82 if(TestData.Contains("Size"))
83 {
84 size = TestData.GetValue("Size");
85 }
86 Log.Comment("Size is " + size);
87
88 var transparency;
89 if(TestData.Contains("Transparency"))
90 {
91 transparency = TestData.GetValue("Transparency");
92 }
93 Log.Comment("Transparency is " + transparency);
94 }
95
96 function ClassCleanup()
97 {
98 Log.Comment("Calling class cleanup");
99 return true;
100 }
101
102 function MethodSetup()
103 {
104 Log.Comment("Calling method setup");
105 var size;
106 if(TestData.Contains("Size"))
107 {
108 size = TestData.GetValue("Size");
109 }
110 Log.Comment("Size is " + size);
111
112 var transparency;
113 if(TestData.Contains("Transparency"))
114 {
115 transparency = TestData.GetValue("Transparency");
116 }
117 Log.Comment("Transparency is " + transparency);
118 return true;
119 }
120
121 function MethodCleanup()
122 {
123 Log.Comment("Calling method cleanup");
124 return true;
125 }
126
127 function TestOne()
128 {
129 Log.Comment("Calling TestOne");
130 var size;
131 if(TestData.Contains("Size"))
132 {
133 size = TestData.GetValue("Size");
134 }
135 Log.Comment("Size is " + size);
136
137 var transparency;
138 if(TestData.Contains("Transparency"))
139 {
140 transparency = TestData.GetValue("Transparency");
141 }
142 Log.Comment("Transparency is " + transparency);
143 }
144
145 function TestTwo()
146 {
147 Log.Comment("Calling TestTwo");
148 var caption = "NoCaption";
149 Log.Comment("Initial caption: " + caption);
150
151 if(TestData.Contains("Caption"))
152 {
153 caption = TestData.GetValue("Caption");
154 }
155 Log.Comment("Caption is " + caption);
156
157 var size;
158 if(TestData.Contains("Size"))
159 {
160 size = TestData.GetValue("Size");
161 }
162 Log.Comment("Size is " + size);
163
164 var transparency;
165 if(TestData.Contains("Transparency"))
166 {
167 transparency = TestData.GetValue("Transparency");
168 }
169 Log.Comment("Transparency is " + transparency);
170 }
171 ]] >
172 </script>
173 </component>
174 </package>
위의 예제에서 6줄과 60줄은 데이터 기반 테스트에 대한 데이터에 대한 액세스를 허용하는 TestData 개체를 선언하고 인스턴스화합니다.
<TestMethodProperty> 및 <TestClassProperty> 태그는 테스트 또는 클래스에 대한 DataSource를 정의하는 줄입니다. VBSampleTests에서 TestOne 에는 WMI 쿼리 가 DataSource로 있습니다. 매개 변수 레이블 및 캡션TestOne의 설정, 정리 및 테스트 메서드에 사용할 수 있습니다. 동일한 클래스에서 TestTwo 에는 여러 DataSources가 정의되어 있습니다. 첫 번째는 Table 기반 DataSource이고, 두 번째는 TestOne과 동일한 WMI 기반 DataSource입니다.
TAEF는 각 DataSource 속성에 대한 매개 변수 집합의 결합 확장을 생성합니다. 각 테스트 메서드 호출에 대해 하나의 매개 변수 집합을 사용할 수 있습니다. WMI 쿼리가 4개의 결과 집합(Win32_Volume)을 반환하고 테이블 기반 DataSource에 3개의 행이 있는 경우 TestOne 은 WMI 쿼리가 반환하는 각 Win32_Volume 한 번씩 네 번 실행됩니다. 반면 TestTwo 는 테이블이 지정하는 Win32_Volume 데이터와 행의 각 조합에 대해 12(4 X 3)를 실행합니다. 연결된 설정 및 정리 메서드에서도 데이터를 사용할 수 있습니다.
JScriptSampleTests에서 데이터 기반 클래스의 예를 볼 수 있습니다. 이 예제는 클래스 수준에서 DataSource 를 지정하기 때문에 테스트 및 클래스 수준 설정 및 정리 메서드뿐만 아니라 모든 테스트 메서드에서도 데이터를 사용할 수 있습니다. TestTwo는 데이터 기반 클래스 내의 데이터 기반 테스트이므로 클래스 수준의 DataSource 데이터와 테스트 수준의 데이터를 TestTwo에 사용할 수 있습니다.
스크립트 테스트에 사용할 수 있는 데이터 형식
다음 매개 변수 형식은 스크립팅 언어에 사용할 수 있습니다. 테이블 기반 데이터 기반 테스트에서 지정할 수 있는 형식입니다. 기본 매개 변수 형식은 String 또는 BSTR ( VT_BSTR 나타내기)입니다.
테이블 기반 DataSource의 매개 변수 형식 섹션에서는 스크립팅 언어로 테스트를 작성하는 동안 사용 가능한 매개 변수 형식(네이티브 및 관리 코드)을 보는 방법을 보여 줍니다.
데이터 기반 스크립트 실행
/listproperties 옵션은 메타데이터뿐만 아니라 테스트의 각 호출에 사용할 수 있는 데이터도 나열합니다. (전체 dll에서 /listproperties 옵션을 실행하는 것은 판독기에게 연습으로 남아 있습니다.) 다음 예제에서는 선택 쿼리 언어를 사용하여 VBSampleTests에서 TestOne 호출을 선택합니다.
f:\spartadev.binaries.x86chk\WexTest\CuE\TestExecution>te Examples\DataDrivenTest.wsc /listproperties /name:VBSampleTests::TestOne*
Test Authoring and Execution Framework v.R10 Build 6.1.6939.0 For x86
f:\spartadev.binaries.x86chk\WexTest\CuE\TestExecution\Examples\DataDrivenTest.wsc
VBSampleTests
VBSampleTests::TestOne#0
Property[DataSource] = WMI:SELECT Label, Caption FROM Win32_Volume
Data[Caption] = C:\
Data[Label] =
VBSampleTests::TestOne#1
Property[DataSource] = WMI:SELECT Label, Caption FROM Win32_Volume
Data[Caption] = D:\
Data[Label] = New Volume
VBSampleTests::TestOne#2
Property[DataSource] = WMI:SELECT Label, Caption FROM Win32_Volume
Data[Caption] = F:\
Data[Label] = New Volume
VBSampleTests::TestOne#3
Property[DataSource] = WMI:SELECT Label, Caption FROM Win32_Volume
Data[Caption] = E:\
Data[Label] = New Volume
VBSampleTests::TestOne#4
Property[DataSource] = WMI:SELECT Label, Caption FROM Win32_Volume
Data[Caption] = G:\
Data[Label] = New Volume
VBSampleTests::TestOne#5
Property[DataSource] = WMI:SELECT Label, Caption FROM Win32_Volume
Data[Caption] = H:\
Data[Label] = New Volume
VBSampleTests::TestOne#6
Property[DataSource] = WMI:SELECT Label, Caption FROM Win32_Volume
Data[Caption] = K:\
Data[Label] =
/listproperties 옵션은 TAEF가 각 Win32_Volume 대해 한 번씩 테스트 메서드 VBSampleTests::TestOne을 7번 호출했음을 보여 줍니다. 각 호출에 대해 TAEF는 각 호출을 구분하기 위해 테스트 메서드에 암시적 인덱 스를 추가합니다. 또한 테스트 메서드의 각 호출에 사용할 수 있는 데이터 및 메타데이터를 볼 수 있습니다.
/listproperties 옵션의 정보를 사용하여 데이터 값 또는 인덱스 값을 기반으로 하는 선택 쿼리를 적용하여 실행할 테스트 호출을 더 세밀하게 제어할 수 있습니다. 다음 예제에서는 캡션 E:\인 호출만 실행하는 방법을 보여줍니다.
te Examples\DataDrivenTest.wsc /select:"@Name='VBSampleTests::TestOne*' and @Data:Caption='E:\'"
다음 명령은 인덱스 를 사용하여 동일한 테스트를 선택합니다.
te Examples\DataDrivenTest.wsc /select:"@Name='VBSampleTests::TestOne*' and @Data:Index=3"
스크립트 테스트에서 PICT 기반 및 경량 데이터 기반 테스트를 사용하는 것은 판독기에게 연습으로 남아 있습니다.