Nant xmlpeek问题

时间:2011-06-17 09:13:48

标签: nant

我目前正在尝试使用nant任务从PartCover解析coverage文件。问题是结构需要一些计数。要做到这一点,我正在查看http://www.russellallen.info/post/Automating-Test-Coverage-with-PartCover-NUnit-and-Nant.aspx上发布的示例,确切地说是第4步。

我写了这样的剧本:

<!-- Generate the report and put it on TeamCity -->
  <target name="PartCoverReport">
    <!-- Read out the amount of lines covered and divide it by the number of hits, more than 90 is passed. -->
    <xmlpeek file="${Paths.Output}\Coverage.xml" xpath="sum(//Type/Method/pt/@len)" property="Test.NumLines1" failonerror="false"/>
    <xmlpeek file="${Paths.Output}\Coverage.xml" xpath="sum(//Type/Method[count(pt)=0]/@bodysize)" property="Test.NumLines2" failonerror="false"/>
    <xmlpeek file="${Paths.Output}\Coverage.xml" xpath="sum(//Type/Method/pt[@visit>0]/@len)" property="Test.LinesCovered" failonerror="false"/>
    <property name="Test.ActualCoverage" value="${double::parse(Test.LinesCovered) / (double::parse(Test.NumLines1) + double::parse(Test.NumLines2)}" />
    <fail if="${double::parse(Test.ActualCoverage) &lt; double::parse(Test.MinimumCoverage)}" message="The solution currently has ${double::parse(Test.ActualCoverage) * 100}% coverage, less than the required 90%" />

    <!-- Check if we need to include the querycount -->
    <if test="${Tests.CountQueries == 'yes'}">
      <readregistry property="TotalQueryCount" key="Software\Tenforce\TestStatistics\TotalQueryCount" hive="LocalMachine" />
      <echo message="##teamcity[buildStatisticValue key='totalQueryCount' value='${TotalQueryCount}']" />
      <readregistry property="AverageQueryCountPerTestRounded" key="Software\Tenforce\TestStatistics\AverageQueryCountPerTestRounded" hive="LocalMachine" />
      <echo message="##teamcity[buildStatisticValue key='averageQueryCountPerTest' value='${math::round(AverageQueryCountPerTestRounded)}']" />
      <readregistry property="AverageQueryCountPerTest" key="Software\Tenforce\TestStatistics\AverageQueryCountPerTest" hive="LocalMachine" />
      <echo message="##teamcity[buildStatus text='{build.status.text}, coverage: ${CoveragePercent}%, queries: ${TotalQueryCount}-${AverageQueryCountPerTest}']" />
    </if>

    <!-- If no query count is needed, then just display the output -->
    <if test="${Tests.CountQueries != 'yes'}">
      <echo message="##teamcity[buildStatus text='{build.status.text}, coverage: ${Test.ActualCoverage}%']" />
    </if>
  </target>

但是,当我查看teamcity输出时,它表示Xpath无效:

[10:46:55]: NAnt output:
[10:46:55]: [exec] Target WorkingSetSize: 115511296
[10:46:55]: [exec] Total 0 bytes
[10:46:55]: PartCoverReport:
[10:46:55]: [xmlpeek] Peeking at 'c:\Robinson\Output\Coverage.xml' with XPath expression 'sum(//Type/Method/pt/@len)'.
[10:46:55]: [xmlpeek] C:\Robinson\trunk\Scripts\NantScripts\NantTestsRunner.build(371,6):
[10:46:55]: [xmlpeek] Failed to select node with XPath expression 'sum(//Type/Method/pt/@len)'.
[10:46:55]: [xmlpeek] Expression must evaluate to a node-set.
[10:46:55]: [xmlpeek] Peeking at 'c:\Robinson\Output\Coverage.xml' with XPath expression 'sum(//Type/Method[count(pt)=0]/@bodysize)'.
[10:46:55]: [xmlpeek] C:\Robinson\trunk\Scripts\NantScripts\NantTestsRunner.build(372,6):
[10:46:55]: [xmlpeek] Failed to select node with XPath expression 'sum(//Type/Method[count(pt)=0]/@bodysize)'.
[10:46:55]: [xmlpeek] Expression must evaluate to a node-set.
[10:46:55]: [xmlpeek] Peeking at 'c:\Robinson\Output\Coverage.xml' with XPath expression 'sum(//Type/Method/pt[@visit>0]/@len)'.
[10:46:55]: [xmlpeek] C:\Robinson\trunk\Scripts\NantScripts\NantTestsRunner.build(373,6):
[10:46:55]: [xmlpeek] Failed to select node with XPath expression 'sum(//Type/Method/pt[@visit>0]/@len)'.
[10:46:55]: [xmlpeek] Expression must evaluate to a node-set.
[10:46:55]: BUILD FAILED - 3 non-fatal error(s), 24 warning(s)

我正在尝试用xml-peek操作吗?

2 个答案:

答案 0 :(得分:1)

我还没看过剧本,但首先要确保你至少安装了NAnt版本0.91-alpha1(2010年5月29日)。 Release notes州,他们在此版本中对count() xmlpeek进行了改进。

答案 1 :(得分:0)

我为Nant编写了自己的C#插件,允许我现在在表达式中使用任何类型的Xpath。