No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

274 líneas
7.8KB

  1. <%
  2. '********************************************************************
  3. ' Name: ASPUnitRunner.asp
  4. '
  5. ' Purpose: Contains the UnitRunner class which is used to render the unit testing UI
  6. '********************************************************************
  7. '********************************************************************
  8. ' Include Files
  9. '********************************************************************
  10. %>
  11. <!-- #include file="ASPUnit.asp"-->
  12. <%
  13. Const ALL_TESTCONTAINERS = "All Test Containers"
  14. Const ALL_TESTCASES = "All Test Cases"
  15. Const FRAME_PARAMETER = "UnitRunner"
  16. Const FRAME_SELECTOR = "selector"
  17. Const FRAME_RESULTS = "results"
  18. Const STYLESHEET = "aspunit/include/ASPUnit.css"
  19. Const SCRIPTFILE = "aspunit/include/ASPUnitRunner.js"
  20. Class UnitRunner
  21. Private m_dicTestContainer
  22. Private Sub Class_Initialize()
  23. Set m_dicTestContainer = CreateObject("Scripting.Dictionary")
  24. End Sub
  25. Public Sub AddTestContainer(oTestContainer)
  26. m_dicTestContainer.Add TypeName(oTestContainer), oTestContainer
  27. End Sub
  28. Public Function Display()
  29. If (Request.QueryString(FRAME_PARAMETER) = FRAME_SELECTOR) Then
  30. DisplaySelector
  31. ElseIf (Request.QueryString(FRAME_PARAMETER) = FRAME_RESULTS) Then
  32. DisplayResults
  33. Else
  34. ShowFrameSet
  35. End if
  36. End Function
  37. '********************************************************************
  38. ' Frameset
  39. '********************************************************************
  40. Private Function ShowFrameSet()
  41. %>
  42. <HTML>
  43. <HEAD>
  44. <TITLE>ASPUnit Test Runner</TITLE>
  45. </HEAD>
  46. <FRAMESET ROWS="70, *" BORDER=0 FRAMEBORDER=0 FRAMESPACING=0>
  47. <FRAME NAME="<% = FRAME_SELECTOR %>" src="<% = GetSelectorFrameSrc %>" marginwidth="0" marginheight="0" scrolling="auto" border=0 frameborder=0 noresize>
  48. <FRAME NAME="<% = FRAME_RESULTS %>" src="<% = GetResultsFrameSrc %>" marginwidth="0" marginheight="0" scrolling="auto" border=0 frameborder=0 noresize>
  49. </FRAMESET>
  50. <%
  51. End Function
  52. Private Function GetSelectorFrameSrc()
  53. GetSelectorFrameSrc = Request.ServerVariables("SCRIPT_NAME") & "?" & FRAME_PARAMETER & "=" & FRAME_SELECTOR
  54. End Function
  55. Private Function GetResultsFrameSrc()
  56. GetResultsFrameSrc = Request.ServerVariables("SCRIPT_NAME") & "?" & FRAME_PARAMETER & "=" & FRAME_RESULTS
  57. End Function
  58. '********************************************************************
  59. ' Selector Frame
  60. '********************************************************************
  61. Private Function DisplaySelector()
  62. %>
  63. <HTML>
  64. <HEAD>
  65. <LINK REL="stylesheet" HREF="<% = STYLESHEET %>" MEDIA="screen" TYPE="text/css">
  66. <SCRIPT>
  67. function ComboBoxUpdate(strSelectorFrameSrc, strSelectorFrameName)
  68. {
  69. document.frmSelector.action = strSelectorFrameSrc;
  70. document.frmSelector.target = strSelectorFrameName;
  71. document.frmSelector.submit();
  72. }
  73. </SCRIPT>
  74. </HEAD>
  75. <BODY>
  76. <FORM NAME="frmSelector" ACTION="<% = GetResultsFrameSrc %>" TARGET="<% = FRAME_RESULTS %>" METHOD=POST>
  77. <TABLE class='Form'>
  78. <TR>
  79. <TD>
  80. <INPUT TYPE="Submit" NAME="cmdRun" class="Submit" VALUE="Run Tests">
  81. </TD>
  82. <TD ALIGN="right">Test:</TD>
  83. <TD>
  84. <SELECT NAME="cboTestContainers" OnChange="ComboBoxUpdate('<% = GetSelectorFrameSrc %>', '<% = FRAME_SELECTOR %>');">
  85. <OPTION><% = ALL_TESTCONTAINERS %>
  86. <%
  87. AddTestContainers
  88. %>
  89. </SELECT>
  90. </TD>
  91. <TD ALIGN="right">Test Method:</TD>
  92. <TD>
  93. <SELECT NAME="cboTestCases">
  94. <OPTION><% = ALL_TESTCASES %>
  95. <%
  96. AddTestMethods
  97. %>
  98. </SELECT>
  99. <TD>
  100. <INPUT TYPE="checkbox" NAME="chkShowSuccess"> Show Passing Tests</INPUT>
  101. </TD>
  102. </TD>
  103. </TR>
  104. </TABLE>
  105. </FORM>
  106. </BODY>
  107. </HTML>
  108. <%
  109. End Function
  110. Private Function AddTestContainers()
  111. Dim oTestContainer, sTestContainer
  112. For Each oTestContainer In m_dicTestContainer.Items()
  113. sTestContainer = TypeName(oTestContainer)
  114. If (sTestContainer = Request.Form("cboTestContainers")) Then
  115. Response.Write("<OPTION SELECTED>" & sTestContainer)
  116. Else
  117. Response.Write("<OPTION>" & sTestContainer)
  118. End If
  119. Next
  120. End Function
  121. Private Function AddTestMethods()
  122. Dim oTestContainer, sContainer, sTestMethod
  123. If (Request.Form("cboTestContainers") <> ALL_TESTCONTAINERS And Request.Form("cboTestContainers") <> "") Then
  124. sContainer = CStr(Request.Form("cboTestContainers"))
  125. Set oTestContainer = m_dicTestContainer.Item(sContainer)
  126. For Each sTestMethod In oTestContainer.TestCaseNames()
  127. Response.Write("<OPTION>" & sTestMethod)
  128. Next
  129. End If
  130. End Function
  131. Private Function TestName(oResult)
  132. If (oResult.TestCase Is Nothing) Then
  133. TestName = ""
  134. Else
  135. TestName = TypeName(oResult.TestCase.TestContainer) & "." & oResult.TestCase.TestMethod
  136. End If
  137. End Function
  138. '********************************************************************
  139. ' Results Frame
  140. '********************************************************************
  141. Private Function DisplayResults()
  142. %>
  143. <HTML>
  144. <HEAD>
  145. <LINK REL="stylesheet" HREF="<% = STYLESHEET %>" MEDIA="screen" TYPE="text/css">
  146. </HEAD>
  147. <BODY>
  148. <%
  149. Dim oTestResult, oTestSuite
  150. Set oTestResult = New TestResult
  151. ' Create TestSuite
  152. Set oTestSuite = BuildTestSuite()
  153. ' Run Tests
  154. oTestSuite.Run oTestResult
  155. ' Display Results
  156. DisplayResultsTable oTestResult
  157. %>
  158. </BODY>
  159. </HTML>
  160. <%
  161. End Function
  162. Private Function BuildTestSuite()
  163. Dim oTestSuite, oTestContainer, sContainer
  164. Set oTestSuite = New TestSuite
  165. If (Request.Form("cmdRun") <> "") Then
  166. If (Request.Form("cboTestContainers") = ALL_TESTCONTAINERS) Then
  167. For Each oTestContainer In m_dicTestContainer.Items()
  168. If Not(oTestContainer Is Nothing) Then
  169. oTestSuite.AddAllTestCases oTestContainer
  170. End If
  171. Next
  172. Else
  173. sContainer = CStr(Request.Form("cboTestContainers"))
  174. Set oTestContainer = m_dicTestContainer.Item(sContainer)
  175. Dim sTestMethod
  176. sTestMethod = Request.Form("cboTestCases")
  177. If (sTestMethod = ALL_TESTCASES) Then
  178. oTestSuite.AddAllTestCases oTestContainer
  179. Else
  180. oTestSuite.AddTestCase oTestContainer, sTestMethod
  181. End If
  182. End If
  183. End If
  184. Set BuildTestSuite = oTestSuite
  185. End Function
  186. Private Function DisplayResultsTable(oTestResult)
  187. %>
  188. <TABLE BORDER="1" class='Results'>
  189. <TR><TH WIDTH="10%" class="Type">Type</TH><TH WIDTH="20%" class="Test">Test</TH><TH WIDTH="70%" class="Desc">Description</TH></TR>
  190. <%
  191. If Not(oTestResult Is Nothing) Then
  192. Dim oResult
  193. If (Request.Form("chkShowSuccess") <> "") Then
  194. For Each oResult in oTestResult.Successes
  195. Response.Write(" <TR CLASS=""success""><TD class='Type'>Success</TD><TD class='Test'>" & TestName(oResult) & "</TD><TD class='Desc'>" & oResult.Source & oResult.Description & "</TD></TR>")
  196. Next
  197. End If
  198. For Each oResult In oTestResult.Errors
  199. Response.Write(" <TR CLASS=""error""><TD class='Type'>Error</TD><TD class='Test'>" & TestName(oResult) & "</TD><TD class='Desc'>" & oResult.Source & " (" & Trim(oResult.ErrNumber) & "): " & oResult.Description & "</TD></TR>")
  200. Next
  201. For Each oResult In oTestResult.Failures
  202. Response.Write(" <TR CLASS=""warning""><TD class='Type'>Failure</TD><TD class='Test'>" & TestName(oResult) & "</TD><TD class='Desc'>" & oResult.Description & "</TD></TR>")
  203. Next
  204. Response.Write " <TR><TD ALIGN=""center"" COLSPAN=3 class='" & ResultRowClass(oTestResult) & "'>" & "Tests: " & oTestResult.RunTests & ", Errors: " & oTestResult.Errors.Count & ", Failures: " & oTestResult.Failures.Count & "</TD></TR>"
  205. End If
  206. %>
  207. </TABLE>
  208. <%
  209. End Function
  210. Private Function ResultRowClass(oTestResult)
  211. if oTestResult.Errors.Count > 0 then
  212. ResultRowClass = "error"
  213. elseif oTestResult.Failures.Count > 0 then
  214. ResultRowClass = "warning"
  215. elseif oTestResult.Successes.Count > 0 then
  216. ResultRowClass = "success"
  217. end if
  218. End Function
  219. Public Sub OnStartTest()
  220. End Sub
  221. Public Sub OnEndTest()
  222. End Sub
  223. Public Sub OnError()
  224. End Sub
  225. Public Sub OnFailure()
  226. End Sub
  227. Public Sub OnSuccess()
  228. End Sub
  229. End Class
  230. %>

Powered by TurnKey Linux.