C# 開発環境/試験実行環境
C#フォームアプリケーションの開発/試験環境メモです。
PC環境
Microsoft Visual Studio Community 2015(以降VS)
これがなくては始まりません。
インストール、使用方法などは省略します。
Nunit
単体試験テストフレームワークです。
VSのパッケージ管理(NuGet)からインストール可能ですが、NuGetを知る前に
入れてしまっていました。3.0.1がCurrentでしたが、使用例の多い2.6.4を入れました。
NUnit Test Adapter
Adapterは、Visual Studio内でNunitを実行するプラグインです。
VS - [ツール]-[拡張機能と更新プログラム]でオンライン検索/ダウンロード
OpenCover
カバレッジ測定ツールです。これもNuGetでインストール可能のようでしたが、GitHubのreleaseから、4.6.210msiをインストールしました。
Releases · OpenCover/opencover · GitHub
ReportGenerator
本当はNunite Test Adapterと同様に、Microsoft Visual Studioギャラリーにある「OpenCover UI」を使用しようとしましたが、Nunitとの関連設定がわからなかった為
本ツールを使用しhtml形式で見れるようにしました。
Releases · danielpalme/ReportGenerator · GitHub
なお導入手順および、バッチファイルの書き方まで以下を参考にさせて頂きました。
Codeer.Friendly
GUI操作をプログラミングできます。Nunitと併用してフォームコントロール操作をプログラムすることで、シナリオ実行をすることができます。
インストール手順、詳細情報はいかにあります(よく記載されています)
私の場合もインストールは、NuGetで行いました。詳細情報を参考に以下(4個)を入れました。
- Codeer.Friendy(結局は使っていない)
- Codeer,Friendy.Windows
- Codeer,Friendy.Windows.Grasp
- Ong.Friendy.FormsStandardControls
上記を入れた目的は、ボタンなどのコントロールイベントハンドラの自動実行を行う
ためです。簡単なアプリケーションを作成しました。
WindwosFormApplication1
Form1.cs
using System;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private int mNumClick;
public Form1()
{
InitializeComponent();
mNumClick = 0;
}private void button1_Click(object sender, EventArgs e)
{
lstTest.Items.Add(new clsFunction(mNumClick.ToString()));
mNumClick++;
}private void btn2_Click(object sender, EventArgs e)
{
if(lstTest.SelectedIndex != -1)
{
lstTest.Items.RemoveAt(lstTest.SelectedIndex);
}}
}
}
WindwosFormApplication1Tests
clsForm1Test.cs
using NUnit.Framework;
using Codeer.Friendly.Dynamic;
using Codeer.Friendly.Windows;
using System.Diagnostics;
using Codeer.Friendly.Windows.Grasp;
using System.Windows.Forms;
using Ong.Friendly.FormsStandardControls;
using WindowsFormsApplication1;namespace WindowsFormsApplication11Tests
{
[TestFixture]
class clsForm1Test
{
WindowsAppFriend _app;[TestFixtureSetUp]
public void TestFixtureSetUp()
{
_app = new WindowsAppFriend(Process.Start("WindowsFormsApplication1.exe"));
}
[TestFixtureTearDown]
public void TestFixtureTearDown()
{
Process.GetProcessById(_app.ProcessId).CloseMainWindow();
}[Test]
public void Test()
{
//MainFormを取得
dynamic mainFormCore = _app.Type<Application>().OpenForms[0];
var mainForm = new WindowControl(mainFormCore);//GUI mapping
var _button1 = new FormsButton(mainFormCore.btn1);
var _button2 = new FormsButton(mainFormCore.btn2);
var _list = new FormsListBox(mainFormCore.lstTest);//シナリオ>>>>>>>>>>>>>>>>
//listへのアイテム追加
_button1.EmulateClick();
_button1.EmulateClick();
//listからのアイテム削除
_list.EmulateChangeSelectedIndex(0);
_button2.EmulateClick();
_list.EmulateChangeSelectedIndex(0);
_button2.EmulateClick();
_button2.EmulateClick();//listへのアイテム追加
_button1.EmulateClick();//シナリオ<<<<<<<<<<<<<<<<
//test結果検証
var data = (clsFunction)_list.Dynamic().Items[0]; ★Assert.AreEqual(1, _list.ItemCount);
}
}
}
詰まったところは、以下2件のみでした(いずれも詳細情報に記載あります)
以上
C#プログラミング入門―「オブジェクト指向」の「プログラミング手法」を基礎から解説 (I・O BOOKS)
- 作者: 出井秀行
- 出版社/メーカー: 工学社
- 発売日: 2011/05/12
- メディア: 単行本
- クリック: 4回
- この商品を含むブログを見る