在指定機器上關掉該假警報測試
[Test]
public void Test(){
if (Environment.MachineName.ToUpper() == "BAD MACHINE")
Assert.Ignore("this test caused false alarms on BAD MACHINE");
}
在指定機器上關掉該假警報測試
[Test]
public void Test(){
if (Environment.MachineName.ToUpper() == "BAD MACHINE")
Assert.Ignore("this test caused false alarms on BAD MACHINE");
}
準備工作
測試安裝檔
注意:
一般category的使用方式如下:
[Test, Category("IntegrationTest")]
void Test1(){.....}
----------------
一個避免寫錯與免記憶負擔的技巧:
建立一個namespace,內含一些class,用來表示所有測試的category:
namespace TestCategory
{
class UnitTest : CategoryAttribute { }
class IntegrationTest : CategoryAttribute { }
}
使用方式:
[Test, TestCategory.IntegrationTest]
void Test1(){.....}
CruiseControl預設不會產生專案統計報表。
欲獲得統計報表,最簡單的設定方式是在ccnet.config中,在欲產生報表的project的<publishers>區段加入<statistics/>。如下所示:
<publishers>
<xmllogger/>
<statistics/>
</publishers>
專案執行成功後,可以在幾個地方看到統計資料報表:
要客製化報表內容可以使用如下的設定方式:
<statistics>
<statisticList>
<statistic name="TestCount" xpath="count(//MyTests/Test)"/>
<statistic name="TestFailures" xpath="count(//MyTests/Test[@success='False'])"/>
<statistic name="TestIgnored" xpath="count(//MyTests/Test[@success='Ignore'])"/>
</statisticList>
</statistics>
此範例自訂了三個statistics:TestCount, TestFailures, 以及TestIgnored。利用xpath來指定所要產生的數值。
若專案有使用nunit,只要<statistics/>有設定,就會自行產出上述三個statistics,無須使用客製化方式來設定。
測試程式:
[TestFixture]
public class Class1
{
[Test, Category("c1")]
public void test1()
{
Console.WriteLine("test1");
}
[Test, Category("c2")]
public void test2()
{
Console.WriteLine("test2");
}
[Test]
public void test3()
{
Console.WriteLine("test3");
}
}
指令與結果:
C:\Program Files\NUnit 2.4.3\bin>nunit-console.exe c:\temp\cl2\bin\Debug\cl2.dll -include=c1
Included categories: c1
.test1
Tests run: 1, Failures: 0, Not run: 0, Time: 0.078 seconds
C:\Program Files\NUnit 2.4.3\bin>nunit-console.exe c:\temp\cl2\bin\Debug\cl2.dll -include=c1,c2
Included categories: c1,c2
.test1
.test2
Tests run: 2, Failures: 0, Not run: 0, Time: 0.094 seconds
C:\Program Files\NUnit 2.4.3\bin>nunit-console.exe c:\temp\cl2\bin\Debug\cl2.dll -exclude=c1
Excluded categories: c1
.test2
.test3
Tests run: 2, Failures: 0, Not run: 0, Time: 0.078 seconds
devenv "MySolution.sln" /build Release /project MyProject /projectconfig Release
上述用法主要用於編譯C++專案,若要編譯C#或VB.NET專案,可以使用msbuild
SELECT p.value AS __color__,
id AS ticket, summary, version, milestone, t.type AS type,
(CASE status WHEN 'assigned' THEN owner||' *' ELSE owner END) AS owner,
Datetime(Datetime(changetime,'unixepoch'), 'localtime') as changed,
time AS created,
changetime AS _changetime, description AS _description,
reporter AS _reporter
FROM ticket t, enum p
WHERE status IN ('new', 'assigned', 'reopened')
AND p.name = t.priority AND p.type = 'priority'
ORDER BY changetime desc
changetime原先的內容為Julianday,轉成可閱讀的unix時間格格式後,再轉換成localtime。
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:variable name="report.list" select="//我的測試報告"/>
<xsl:template match="/">
<!-- 有內容才顯示報告 -->
<xsl:if test="count($report.list)>0">
<table class="section-table" cellpadding="2" cellspacing="0" border="0" width="98%">
<tr>
<!-- 根據實際欄位個數調整colspan -->
<td class="sectionheader" colspan="5">
我的測試報告: 共有<xsl:value-of select="count($report.list)"/>份報告
</td>
</tr>
<tr>
<xsl:if test="position() mod 2=0">
<xsl:attribute name="class">section-oddrow</xsl:attribute>
</xsl:if>
<xsl:if test="position() mod 2!=0">
<xsl:attribute name="class">section-evenrow</xsl:attribute>
</xsl:if>
<td>欄位1標題</td>
<td>欄位2標題</td>
<td>欄位3標題</td>
<td>欄位4標題</td>
<td>欄位5標題</td>
</tr>
<xsl:apply-templates select="$report.list"/>
</table>
</xsl:if>
</xsl:template>
<!-- 開始格式化報告內容 -->
<xsl:template match="報告">
<tr>
<!-- 美化 -->
<xsl:if test="position() mod 2=0">
<xsl:attribute name="class">section-oddrow</xsl:attribute>
</xsl:if>
<xsl:if test="position() mod 2!=0">
<xsl:attribute name="class">section-evenrow</xsl:attribute>
</xsl:if>
<!-- 資料 -->
<td class="section-data" valign="top">
<xsl:value-of select="欄位1資料"/>
</td>
<td class="section-data" valign="top">
<xsl:value-of select="欄位2資料"/>
</td>
<td class="section-data" valign="top">
<xsl:value-of select="欄位3資料"/>
</td>
<td class="section-data" valign="top">
<xsl:value-of select="欄位4資料"/>
</td>
<td class="section-data" valign="top">
<xsl:value-of select="欄位5資料"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select="//unittest-results"/>
</xsl:template>
<xsl:template match="unittest-results">
<html>
<body>
<h3>
UnitTest++測試了<xsl:value-of select="@tests"/>筆資料,<xsl:value-of select="@failedtests"/>筆失敗,費時<xsl:value-of select="@time"/>秒
</h3>
<table>
<tr>
<th>Suite</th>
<th>測試</th>
<th>費時</th>
<th>訊息</th>
</tr>
<xsl:for-each select="test">
<xsl:if test="count(failure)>0">
<tr bgcolor="#ffaaaa">
<td>
<xsl:value-of select="@suite"/>
</td>
<td>
<font color="green">
<xsl:value-of select="@name"/>
</font>
</td>
<td>
<xsl:value-of select="@time"/>
</td>
<td>
<xsl:value-of select="failure/@message"/>
</td>
</tr>
</xsl:if>
<xsl:if test="count(failure)=0">
<tr>
<td>
<xsl:value-of select="@suite"/>
</td>
<td>
<font color="green">
<xsl:value-of select="@name"/>
</font>
</td>
<td>
<xsl:value-of select="@time"/>
</td>
<td></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>