1.7 reportNg之classresult.html.vm修改

测试结果展示优化
本文介绍了一个改进的测试结果展示方式,通过使用HTML和脚本语言,实现了测试方法的详细结果显示,包括方法描述、持续时间、输出、依赖项、异常堆栈、截图等功能,提升了测试报告的可读性和实用性。

1、classresult.html.vm修改后的源码如下

注:

①提供了截图显示及根据鼠标焦点放大缩小图片功能

②增加了endtime、shot、description等class

## This macro formats the results (whether passed, skipped or failed) of the test
## methods in a single class for inclusion in the HTML report.  It assumes that the
## the results for the class are in a variable called $classResults.  $id is a page
## scope variable that is used to assign unique identifiers to divs.

#foreach ($testResult in $classResults)
<tr>
  <td class="method">
    #set ($testInstanceName = "")
    #if ($testResult.testName)
      #set ($testInstanceName = " ($testResult.testName)")
    #end
    #if ($testResult.method.description && $testResult.method.description.length() > 0)
      <span class="description" title="$testResult.method.description">$testResult.name$testInstanceName </span>
    #else
      $testResult.name$testInstanceName
    #end
  </td>
  <td class="duration">
    $utils.formatDuration($testResult.startMillis, $testResult.endMillis)s
  </td>
  <td class="result">
    #set ($output = $utils.getTestOutput($testResult))
    #if ($output.size() > 0)
        <div class="testOutput">
          #foreach( $line in $output )
            #if ($meta.shouldEscapeOutput())
              $utils.escapeHTMLString($line)<br />
            #else
              $line
            #end
          #end
        </div>
    #end
    ## Display the dependencies for skipped test methods.
    #if ($testResult.status == 3) ## 3 means skipped.
      #if( $utils.hasDependentGroups($testResult) )
        <i>$messages.getString("dependsOnGroups"): </i>
        <span class="dependency">$utils.getDependentGroups($testResult)</span>
        <br />
      #end
      #if ($utils.hasDependentMethods($testResult))
        <i>$messages.getString("dependsOnMethods"): </i>
        <span class="dependency">$utils.getDependentMethods($testResult)</span>
      #end
      #if ($utils.hasSkipException($testResult))
       <i>$messages.getString("skipped.reason"): </i>
       <span class="dependency">$utils.getSkipExceptionMessage($testResult)</span>
      #end
    #end

    #if ($utils.hasArguments($testResult))
      <i>$messages.getString("methodArguments"): </i><span class="arguments">$utils.getArguments($testResult)</span><br />
    #end
    #if ($testResult.throwable && ( $testResult.status == 2 || $meta.shouldShowExpectedExceptions()))
    <a href="javascript:toggleElement('exception-$id', 'block')" title="$messages.getString("clickToExpandCollapse")"><b>$utils.escapeHTMLString( $testResult.throwable.toString() )</b></a><br />
    <div class="stackTrace" id="exception-$id">
      #foreach ($element in $testResult.throwable.stackTrace)
        $utils.escapeHTMLString( $element.toString() )<br />
      #end
      #set ($causes = $utils.getCauses($testResult.throwable))
      #foreach ($throwable in $causes)
        #set ($id = $id + 1)
        <b>$messages.getString("causedBy"): </b> <a href="javascript:toggleElement('exception-$id', 'block')" title="Click to expand/collapse">$utils.escapeHTMLString( $throwable.toString() )</a><br />
        <div class="stackTrace" id="exception-$id">
          #foreach ($element in $throwable.stackTrace)
            $utils.escapeHTMLString($element.toString())<br />
          #end
        </div>
      #end
    </div>
    #end
    #set ($id = $id + 1)
    </td>

    <td class="screenshot">
        #if($testResult.status==2)
          #set($path = $utils.getPathImage($testResult.getMethod()))
            <img src="$path" alt="sdss" onmouseover="bigImg(this)" onmouseout="normalImg(this)" border="0" width="100%" height="180px">
        #end

    </td>
    <td class="description">
        #if ($testResult.method.description && $testResult.method.description.length() > 0)
          $testResult.method.description
    #end
    </td>
    <td class="endtime">
      $utils.dateFormate($testResult.endMillis)
    </td>
</tr>
#end
<script type="text/javascript">
    function bigImg(x) {
        x.style.height = "80%";
        x.style.width = "80%";
        x.style.position = "fixed"
        x.style.left ="150px";
        x.style.top ="10%"

    }
    function normalImg(x) {
        x.style.height = "180px";
        x.style.width = "100%";
        x.style.position = "static"
    }
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值