【C#】 【NUnit】 NUnitForms ~ Hello World編 ~

■ デザイン

* 分かりやすいようにシンプルにする
 * Textbox : 1
 * button : 1

■ サンプルコード

 * デザイン([NUnitFormSample]-[NUnitSampleForm.cs])とは
   別プロジェクト(以下の例では「FormTest」)で、テストクラスを記述する

コード

using NUnit.Extensions.Forms;
using NUnit.Framework;
using NUnitFormSample;

namespace FormTest
{
    [TestFixture]
    public class NUnitFormTest
    {
        private NUnitSampleForm _form;

        [SetUp]
        public void SetUp() // 前処理
        {
            // テスト対象画面の表示
            this._form = new NUnitSampleForm();
            this._form.Show();
        }

        [TearDown]
        public void TearDown() // 後処理
        {
            this._form.Close();
        }

        [Test]
        public void Test1()
        {
            TextBoxTester textTester =
                new TextBoxTester("textBox1");
            Assert.AreEqual(string.Empty, textTester.Text);
            Assert.AreEqual(255, textTester["MaxLength"]);
        }

        [Test]
        public void Test2()
        {
            // 検索ボタンを押下
            ButtonTester buttonTester = new ButtonTester("button1");
            buttonTester.Click();

            TextBoxTester textTester = new TextBoxTester("textBox1");

            Assert.AreEqual("Hello world!", textTester.Text);
        }
    }
}


関連記事

NUnitForms ~ サンプル編 ~

http://blogs.yahoo.co.jp/dk521123/21118440.html

NUnitForms ~ あれこれ編 ~

https://blogs.yahoo.co.jp/dk521123/21717521.html