その時々

その時々で違うんです。特に決まっていないんです。

NUnitAsp2.0とVisualStudio2005によるASP.NET2.0 (VB)テスト

1. http://nunitasp.sourceforge.net/からNUnitAsp2.0をダウンロード

2. http://www.nunit.org/からNUnit2.5をダウンロード

3. NUnit-2.5.2.9222.msiを起動しインストール

4. NUnitAsp-2.0.zipを展開する


 WebFormTestCase等がこのバージョんだと使用できない。
 NUnitAdapter.cs内に存在するようなので、DLLを作成する


1. [新しいプロジェクト]-[Visual C#]-[クラスライブラリ] NUnitAdapter

2. Class1は削除し、NUnitAspの展開したフォルダ内のbinの下にあるNUnitAdapter.csを追加する。

3. [参照の追加]
   ・C:\Program Files\NUnit 2.5.2\bin\net-2.0\framework\nunit.framework.dll
   ・展開先NUnitAsp-2.0\bin\NUnitAsp.dll

4. リビルド
objフォルダ内のReleaseの下にNUnitAdapter.dllが作成される


1. VisualStudio2005を起動し[新しいWebサイト]http://localhost/NUnitTestSiteを作成

2. HTMLソースのDOC TYPEのアドレスを削除する(当環境のみかもしれない)



3. Label、TextBox、Buttonを1つずつ配置

4. Button1_Clickイベントに次のコードを追加
  
  Label1.Text = TextBox1.Text

5. [デバッグ]→[デバッグを有効にするために Web.config ファイルを変更する]

6. Webサイトを閉じる


1. [新しいプロジェクト]-[コンソールアプリケーション] NUnitTest  (VB)

2. [参照の追加] - C:\Program Files\NUnit 2.5.2\bin\net-2.0\framework\nunit.framework.dll
  ・C:\Program Files\NUnit 2.5.2\bin\net-2.0\framework\nunit.framework.dll
  ・展開先NUnitAsp-2.0\bin\NUnitAsp.dll
  ・作成したNUnitAdapter.dll

3. クラスの追加

4. 以下のソースをコーディング

Imports NUnit.Framework
Imports NUnit.Extensions.Asp
Imports NUnit.Extensions.Asp.AspTester

_
Public Class TestClass
Inherits WebFormTestCase

_
Sub Test()
Browser.GetPage("http://localhost/NUnitTestSite/Default.aspx")

Dim t1 As TextBoxTester = New TextBoxTester("TextBox1")
Dim l1 As LabelTester = New LabelTester("Label1")
Dim b1 As ButtonTester = New ButtonTester("Button1")

t1.Text = "aaa"
b1.Click()
AssertEquals(l1.Text, t1.Text)

End Sub
End Class


 コードの内容
 ・ローカルのテストサイトを取得
 ・各コントロールのオブジェクトを作成
 ・TextBox1に"aaa"という文字列を接と
 ・Button1をクリック
 ・Label1に"aaa"が入力されるので、Label1のテキストとTextBox1のテキストを比較
  ※エラーの場合はNunitで引っかかる


5. [デバッグの開始]

6. [すべてを保存]


1. スタートメニューより[NUnit 2.5.2]-[Select Runtime]-[NUnit (.NET 2.0)]を起動

2. [Tools]-[Settings]

3. [Visual Studio]-[Enable Visual Studio Support]にチェック

4. [File]-[Open Project]

5. NUnitTestClass.slnを開く

6. Runボタンをクリック