/
GenerateUiTestCasesEntryPoint.cs
100 lines (84 loc) · 4.14 KB
/
GenerateUiTestCasesEntryPoint.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using NextDesign.Desktop;
using NextDesign.Extension;
using System;
using System.Linq;
using System.Windows;
namespace GenerateUiTestCases
{
/// <summary>
/// エクステンションのエントリポイントです
/// </summary>
public class GenerateUiTestCasesEntryPoint : IExtension
{
/// <summary>
/// アプリケーション
/// </summary>
private IApplication App { get; set; }
#region Activate/Deactivate
/// <summary>
/// エクステンションの初期化時の処理です。
/// </summary>
/// <param name="context">エクステンションのコンテキストです。</param>
public void Activate(IContext context)
{
App = context.App;
}
/// <summary>
/// エクステンションの終了前の処理です。
/// </summary>
/// <param name="context">エクステンションのコンテキストです。</param>
public void Deactivate(IContext context)
{
}
#endregion
#region Commands
/// <summary>
/// UI画面の操作仕様から動作確認のためのテストケースを自動作成します。
/// </summary>
/// <param name="c">コマンドコンテキスト</param>
/// <param name="p">コマンドパラメータ</param>
public void GenerateUiTestCases(ICommandContext c, ICommandParams p)
{
// 前提条件を確認します。
var project = App.Workspace.CurrentProject;
var currentModel = App.Window.EditorPage?.CurrentEditorView?.Editor?.Model;
if (currentModel == null)
{
App.Window.UI.ShowMessageBox("対象モデルを表示させてから実行してください。");
return;
}
var testSpec = project.FindChildrenByClass("TestSpec", recursive: true).FirstOrDefault();
if (testSpec == null)
{
App.Window.UI.ShowMessageBox("テスト仕様モデルを作成してから実行してください。");
return;
}
// UI画面ごとにテストグループを作成して、テストケースを追加します。
var uiWindows = currentModel.FindChildrenByClass("UiWindow", recursive: true);
foreach (var uiWindow in uiWindows)
{
// UI画面ごとにテストグループを作成します。
var testGroupModel = testSpec.AddNewModel("TestGroups", "TestGroup");
testGroupModel.SetField("Name", uiWindow.Name);
// UI画面の中からUI部品の操作仕様を抽出します。
var operationModels = uiWindow.FindChildrenByClass("OperationSpec", recursive: true);
// 操作仕様に対応したテストケースを作成します。
foreach (var operationModel in operationModels)
{
var testCaseModel = testGroupModel.AddNewModel("TestCases", "TestCase");
// 操作仕様に基づいてテストケースの名前と期待値を設定します。
var uiElementName = operationModel.Owner.Name; // UI部品の名前
var operation = operationModel.Name; // 操作
var action = operationModel.GetFieldString("Action"); // 動作
var testCaseLabel = $"{uiElementName}・{operation}"; // テストケースの名前
var expectedValue = $"{uiElementName}が{operation}されると、{action}"; // 期待値
testCaseModel.SetField("Name", testCaseLabel);
testCaseModel.SetField("ExpectedValue", expectedValue);
// 操作仕様とテストケース間にトレース関連(導出関連)を結びます。
testCaseModel.Relate("input_OperationSpec", operationModel);
}
}
}
#endregion
}
}