【问题标题】:Nant xmlpeek issueNant xmlpeek 问题
【发布时间】:2014-01-16 23:01:14
【问题描述】:

我目前正在尝试使用 nant 任务从 PartCover 解析覆盖文件。问题是结构需要一些计数。为此,我正在查看发布在 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 操作做什么?

【问题讨论】:

    标签: nant


    【解决方案1】:

    我还没有查看脚本,但首先请确保您至少安装了 NAnt 版本 0.91-alpha1(2010 年 5 月 29 日)。 Release notes 状态,他们在此版本中对 count()xmlpeek 进行了改进。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-06-02
        • 1970-01-01
        • 2010-09-20
        • 1970-01-01
        • 2011-02-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多