Нант проблема xmlpeek - PullRequest
1 голос
/ 17 июня 2011

В настоящее время я пытаюсь проанализировать файл покрытия из PartCover, используя задачу nant.Проблема в том, что структура требует немного подсчета.Чтобы сделать это, я смотрю на пример, размещенный на 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 ]

1 голос
/ 18 июня 2011

Я еще не видел сценарий, но прежде всего убедитесь, что у вас установлена ​​хотя бы версия NAnt 0.91-alpha1 (29 мая 2010 г.). Примечания к выпуску состояние, они имеют улучшения для count() с xmlpeek в этой версии.

0 голосов
/ 21 июня 2011

Я написал свой собственный плагин C # для Nant, который теперь позволяет мне использовать любой тип Xpath в выражении.

...