在指定機器上關掉該假警報測試
[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