星期二, 十月 21, 2008

某些測試在特定機器上老是出現假警報怎麼辦

在指定機器上關掉該假警報測試

[Test]
public void Test(){

if (Environment.MachineName.ToUpper() == "BAD MACHINE")
    Assert.Ignore("this test caused false alarms on BAD MACHINE");

}

星期三, 四月 16, 2008

限制TRAC report中出現的ticket的時間

changetime - strftime('%s','2008-04-01 02:34:56')

星期五, 四月 11, 2008

使用Microsoft Virtual PC 2007 來輔助測試安裝檔

準備工作

  1. 使用MS Virtual PC安裝一個乾淨的Windows XP
  2. Install Virtual Machine Additions
  3. 在設定中開啟"Enable Undo Disks"。(為了還原硬碟狀態)
  4. 在設定中指定一個Shared Folder。 (為了複製程式到Virtual Machine中)
  5. 複製一些需要的安裝工具到Shared Folder,安裝這些工具到Virtual Machine中。
  6. 確認一切無誤後,關閉virtual machine,選擇"Turn Off and Save Changes"。記得勾選"Commit Changes to the Virtual Hard Disk"。

測試安裝檔

  1. 包裝安裝檔
  2. 開啟virtual machine。
  3. 複製安裝檔在Virtual Machine用的Shared Folder。
  4. 安裝安裝檔
  5. 要關閉Virtual Machine重新測試時,請選擇"Turn Off and Delete Changes"。表示要關掉virtual machine,但不要將硬碟的改變存回去。

注意:

  • Virtual PC能夠undo的只有硬碟的狀態,也就是所謂的"changes"
  • 至於"state"則只能凍結目前CPU, Ram的狀態,下次重開virtual machine時,會回到上次凍結的狀態。"state"目前測試的結果是不能undo的。

星期六, 三月 22, 2008

Nunit中避免category寫錯的小技巧

一般category的使用方式如下:

[Test, Category("IntegrationTest")]
void Test1(){.....}

----------------

一個避免寫錯與免記憶負擔的技巧:

建立一個namespace,內含一些class,用來表示所有測試的category:

namespace TestCategory
{
    class UnitTest : CategoryAttribute { }

    class IntegrationTest : CategoryAttribute { }
}

使用方式:

[Test, TestCategory.IntegrationTest]
void Test1(){.....}

星期六, 三月 01, 2008

vim簡易使用說明

  • 插入:i
  • 附加:a
  • 左右:hl
  • 上下:kj
  • 複製游標所在行:yy
  • 還原:u
  • 貼上:p
  • 不儲存直接離開::q!
  • 刪除游標所在字元:x
  • 刪除游標所在文字,然後進入插入模式:ciw

星期四, 二月 28, 2008

設定CruiseControl.NET產生統計報表

CruiseControl預設不會產生專案統計報表。

欲獲得統計報表,最簡單的設定方式是在ccnet.config中,在欲產生報表的project的<publishers>區段加入<statistics/>。如下所示:

<publishers>
    <xmllogger/>
    <statistics/>
</publishers>

專案執行成功後,可以在幾個地方看到統計資料報表:

  1. Dashboard的"View Statistics"網頁
  2. log目錄中的report.xml檔案
  3. log目錄中的statistics.csv檔案

要客製化報表內容可以使用如下的設定方式:

<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,無須使用客製化方式來設定。

星期二, 二月 26, 2008

使用命令列指令指定測試的Nunit類別

測試程式:

[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