次の方法で共有


実行グループ

このセクションに進む前に、TAEF の基本的な実行と、それを使用してテストを作成する方法を理解していることを確認してください。 また、「ユーザー ガイド」に記載されているデータドリブン テストの例のチュートリアルを確認することもできます。

TAEF を使用したシナリオ ベースのテスト

シナリオ レベルのテストについて話すときは、実際には一連のテストについての話であり、ここでは、次のテストの実行は、シナリオの前のテストが成功した場合にのみ意味があります。 場合によっては、前のテストが失敗した場合に、次のテストを実行するために必要なすべての情報が得られない場合もあります。 この目的に向けて、テスト メソッドとして実行の単位を保持し、テスト シナリオを可能にしながら、TAEF は "ExecutionGroup" と呼ばれるものをサポートします。 データ ドリブン テストなどの他の機能を引き続き備えながら、TAEF でシナリオ ベースのテストを行うことができます。 データドリブン テストを活用するようにシナリオを設計する場合は、TAEF によって提供されるデータ ドリブン クラス機能を使用して、クラス レベルでデータドリブン サポートを適用できます。 クラス レベルでデータ ドリブン サポートを適用することで、クラス内のすべてのテストを各行に対して順番に実行できます。

このページでは、クラス内の一連のテストを "ExecutionGroup" として指定する方法に重点を置きます。

実行グループ

実行グループについて説明する前に、TAEF では、クラス内のテストの実行順序が、ネイティブ コードの場合は TEST_METHOD(...) として修飾された順序であるか、マネージド コードの場合はメソッドの前に [TestMethod] プロパティを追加した順序であることに注意し、覚えておくことが重要です。 TAEF では、クラス自体の実行順序は保証されません。

現在、シナリオ ベースのテストでは、実行順序を保証するだけでは不十分な場合があります。シナリオの次のテストに進む前に、シナリオ内のすべての以前のテストが成功したことを保証する必要もあるのです。 ここで、"ExecutionGroup" の概念が役立ちます。

ネイティブの例を考えてみましょう。

1     class ExecutionDependencyExample
2     {
3         BEGIN_TEST_CLASS(ExecutionDependencyExample)
4             TEST_CLASS_PROPERTY(L"ExecutionGroup", L"DependentTests")
5         END_TEST_CLASS()
6
7         TEST_METHOD(Test1)
8         {
9             Log::Comment(L"Test1 passes.");
10        }
11
12        TEST_METHOD(Test2)
13        {
14            Log::Comment(L"Test2 fails.");
15            VERIFY_ARE_EQUAL(2, 3);
16        }
17
18        TEST_METHOD(Test3)
19        {
20            Log::Comment(L"Test3 is blocked; so you shouldn't see this.");
21        }
22    };

上記の C++ ファイル スニペットの 4 行目を参照してください。 この特定のケースでは、クラス ExecutionDependencyExample 内のすべてのテストを、"DependentTests" という名前の "ExecutionGroup" に属するように修飾します。 これは、"Test1"、"Test2"、および "Test3" が "DependentTests" 実行グループの一部であることを意味します。 前述したように、Test1 が正常に実行されて成功した場合にのみ、Test2 が実行されます。 同様に、Test3 は Test2 が正常に実行され、成功した場合にのみ実行されます。

Test2 が失敗するように設計されていることがわかるでしょう (上記の 14 行目と 15 行目を参照)。

Test2 は "DependentTests" "ExecutionGroup" で失敗するため、Test3 は実行されず、代わりにブロックとしてマークされます。 上記のテストを実行して、これが実際に真実であるかどうかを確認しましょう。

te Examples\CPP.ExecutionDependency.Example.dll
Test Authoring and Execution Framework v2.93k for x86

StartGroup: WEX::TestExecution::Examples::ExecutionDependencyExample::Test1
Test1 passes.
EndGroup: WEX::TestExecution::Examples::ExecutionDependencyExample::Test1 
    [Passed]

StartGroup: WEX::TestExecution::Examples::ExecutionDependencyExample::Test2
Test2 fails.
Error: Verify: AreEqual(2, 3) - Values (2, 3) [File: >f:source\executiondependencyexample\executiondependencyexample.cpp,
Function: WEX::TestExecution::Examples::ExecutionDependencyExample::Test2, Line:21] 
EndGroup: WEX::TestExecution::Examples::ExecutionDependencyExample::Test2[Failed] 

StartGroup: WEX::TestExecution::Examples::ExecutionDependencyExample::Test3
Blocked: This test belongs to an execution group and depends on the previous test being executed in the same environment successfully. The dependent test must be selected for execution, must request the same execution environment (e.g. 'ThreadingModel') and must be executed successfully.
EndGroup: WEX::TestExecution::Examples::ExecutionDependencyExample::Test3 [Blocked]

Non-passing Tests:
    WEX::TestExecution::Examples::ExecutionDependencyExample::Test2 [Failed]
    WEX::TestExecution::Examples::ExecutionDependencyExample::Test3 [Blocked]

Summary: Total=3, Passed=1, Failed=1, Blocked=1, Not Run=0, Skipped=0

予測どおりに、Test1 が成功し、Test2 が失敗し、Test3 がブロックされたことに注意してください。 Test3 では、TAEF は Test3 が実行グループに属し、前のテストが正常に実行されなかったことを示すメッセージをログに記録します。

このエラー メッセージには、同じ ExecutionGroup に属する現在のテストが実行される前のすべてのテストを選択する必要があるというメッセージも表示されます。 つまり、実行時に選択条件を使用して Test2 のみを実行しようとすると、同じ ExecutionGroup に属しており、Test2 は Test1 に依存する実行であるためブロックされることがわかります。

te Examples\CPP.ExecutionDependency.Example.dll /name:*Test2*
Test Authoring and Execution Framework v2.9.3k for x86

StartGroup: WEX::TestExecution::Examples::ExecutionDependencyExample::Test2
Blocked: This test belongs to an execution group and depends on the previous test being executed in the same environment successfully. The dependent test must be selected for execution, must request the same execution environment (e.g. 'ThreadingModel') and must be executed successfully.

EndGroup: WEX::TestExecution::Examples::ExecutionDependencyExample::Test2 [Blocked]

Summary: Total=1, Passed=0, Failed=0, Blocked=1, Not Run=0, Skipped=0

ただし、ExecutionGroup で最初のテストである Test1 を選択すると、正常に実行されます。

te Examples\CPP.ExecutionDependency.Example.dll /name:*Test1*
Test Authoring and Execution Framework v2.9.3k for x86
StartGroup: WEX::TestExecution::Examples::ExecutionDependencyExample::Test1
Test1 passes.
EndGroup: WEX::TestExecution::Examples::ExecutionDependencyExample::Test1 [Passed]

Summary: Total=1, Passed=1, Failed=0, Blocked=0, Not Run=0, Skipped=0

また、ExecutionGroup に属していないテストがある場合は、ExecutionGroup 内のテストの実行結果に関係なく実行されます。 クラス内に複数の ExecutionGroup を含めることもできます。 ただし、ExecutionGroup は複数のクラスにまたがることはできません。 その場合は、代わりに、各クラスに 1 つずつ、2 つの個別の ExecutionGroup と見なされます。

また、Test3 は Test2 と同じ環境で実行する必要があるというメッセージも表示されます。 この側面について、もう少し詳しく理解してみましょう。 ExecutionGroup の一部であるということは実際にはシナリオ ベースのテストの一部であることを意味するため、すべてのテストが要求され、同じ環境で実行することが重要になります。 たとえば、ExecutionGroup 内でスレッド モデルが変更されると、ブロックされたテストが表示されます。 たとえば、上記の例では、Test2 は正常に実行されるように設計されていますが、'ThreadingModel' プロパティが 'MTA' に設定されており、Test3 はブロックされます。

別の例を考えてみましょう:Examples\TAEF\CSharp\ExecutionDependentGroupsExample (最新の TAEF リリース共有を参照してください)

1     [TestClass]
2     public class CSharpExecutionDependentGroupsExample
3     {
4         //First Execution Group: Test1, Test2
5         [TestMethod]
6         [TestProperty("ExecutionGroup", "First Execution Group")]
7         public void Test1()
8         {
9             Log.Comment("Part of First Execution Group");
10        }
11        [TestMethod]
12        [TestProperty("ExecutionGroup", "First Execution Group")]
13        public void Test2()
14        {
15            Log.Comment("Part of First Execution Group");
16        }
17
18        //Second Execution Group: Test3, Test4. Test4 fails
19        [TestMethod]
20        [TestProperty("ExecutionGroup", "Second Execution Group")]
21        public void Test3()
22        {
23            Log.Comment("Part of Second Execution Group");
24        }
25        [TestMethod]
26        [TestProperty("ExecutionGroup", "Second Execution Group")]
27        public void Test4()
28        {
29            Log.Comment("Part of Second Execution Group - last in group fails");
30            Verify.IsTrue(false);
31        }
32
33        //Third Execution Group: Test5, Test6, Test7. Test6 fails, Test7 will be blocked.
34        [TestMethod]
35        [TestProperty("ExecutionGroup", "Third Execution Group")]
36        public void Test5()
37        {
38            Log.Comment("Part of Third Execution Group");
39        }
40        [TestMethod]
41        [TestProperty("ExecutionGroup", "Third Execution Group")]
42        public void Test6()
43        {
44            Log.Comment("Part of Third Execution Group - middle in this set of 3 fails");
45            Verify.IsTrue(false);
46        }
47        [TestMethod]
48        [TestProperty("ExecutionGroup", "Third Execution Group")]
49        public void Test7()
50        {
51            Log.Comment("Part of Third Execution Group");
52        }
53
54        //Fourth Execution Group: Test8, Test9
55        [TestMethod]
56        [TestProperty("ExecutionGroup", "Fourth Execution Group")]
57        public void Test8()
58        {
59            Log.Comment("Part of Fourth Execution Group");
60        }
61        [TestMethod]
62        [TestProperty("ExecutionGroup", "Fourth Execution Group")]
63        public void Test9()
64        {
65            Log.Comment("Part of Fourth Execution Group");
66        }
67    }

この例には、4 つの異なる実行グループがあります。

  • "First Execution Group" contains Test1, Test2; 両方が正常に通過するはずです。
  • "Second Execution Group" には、Test3 と Test4 が含まれています。 Test4 はこの ExecutionGroup の最後のテストであり、失敗します。
  • "Third Execution Group" には、Test5、Test6、および Test7 が含まれています。 前の ExecutionGroup の Test4 は失敗しましたが、Test5 は実行され、成功します。 Test6 は失敗するように設計されているため、Test7 はブロックされます。
  • "Fourth Execution Group" には、Test8 と Test9 が含まれています。 もう一度、Test6 が失敗したため、前の ExecutionGroup の Test7 はブロックされましたが、Test8 は正常に実行され、Test9 も同様です。

この例の ExecutionGroups について理解を深めるために、この例のプロパティを一覧表示してみましょう。

te Examples\CSharp.ExecutionDependentGroups.Example.dll /listproperties
Test Authoring and Execution Framework v2.9.3k for x86

        F:\ \Examples\CSharp.ExecutionDependentGroups.Example.dll
            WEX.Examples.CSharpExecutionDependentGroupsExample
                WEX.Examples.CSharpExecutionDependentGroupsExample.Test1
                        Property[ExecutionGroup] = First Execution Group
                WEX.Examples.CSharpExecutionDependentGroupsExample.Test2
                        Property[ExecutionGroup] = First Execution Group

                WEX.Examples.CSharpExecutionDependentGroupsExample.Test3
                        Property[ExecutionGroup] = Second Execution Group
                WEX.Examples.CSharpExecutionDependentGroupsExample.Test4
                        Property[ExecutionGroup] = Second Execution Group

                WEX.Examples.CSharpExecutionDependentGroupsExample.Test5
                        Property[ExecutionGroup] = Third Execution Group
                WEX.Examples.CSharpExecutionDependentGroupsExample.Test6
                        Property[ExecutionGroup] = Third Execution Group
                WEX.Examples.CSharpExecutionDependentGroupsExample.Test7
                        Property[ExecutionGroup] = Third Execution Group

                WEX.Examples.CSharpExecutionDependentGroupsExample.Test8
                        Property[ExecutionGroup] = Fourth Execution Group
                WEX.Examples.CSharpExecutionDependentGroupsExample.Test9
                        Property[ExecutionGroup] = Fourth Execution Group

上記のテストを実行すると、次の出力で予測される実行順序が確認されます。

te Examples\CSharp.ExecutionDependentGroups.Example.dll
Test Authoring and Execution Framework v2.9.3k for x86

StartGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test1

Part of First Execution Group
EndGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test1 [Passed]
StartGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test2

Part of First Execution Group
EndGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test2 [Passed]

StartGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test3

Part of Second Execution Group
EndGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test3 [Passed]
StartGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test4

Part of Second Execution Group - last in group fails
Error: Verify: IsTrue [File: Need_Symbols, Function: Test4, Line: 0] 
Error: [HRESULT: 0x80131604]. Operation failed: 'WEX.Examples.CSharpExecutionDependentGroupsExample.Test4'.
EndGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test4 [Failed]

StartGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test5

Part of Third Execution Group
EndGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test5 [Passed]
StartGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test6

Part of Third Execution Group - middle in this set of 3 fails
Error: Verify: IsTrue [File: Need_Symbols, Function: Test6, Line: 0] 
Error: [HRESULT: 0x80131604]. Operation failed: 'WEX.Examples.CSharpExecutionDependentGroupsExample.Test6'.
EndGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test6 [Failed] 
Error: WEX.Examples.CSharpExecutionDependentGroupsExample.Test7 belongs to an execution group and depends
       on the previous test being executed in the same environment successfully.
Error: Please make sure that the dependent test is selected for execution, requests the same execution .
       environment metadata(e.g. 'ThreadingModel') and that it executed successfully.
StartGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test7
Blocked EndGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test7 [Blocked]

StartGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test8

Part of Fourth Execution Group
EndGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test8 [Passed]
StartGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test9

Part of Fourth Execution Group
EndGroup: WEX.Examples.CSharpExecutionDependentGroupsExample.Test9 [Passed]

Failed Tests:
    WEX.Examples.CSharpExecutionDependentGroupsExample.Test4
    WEX.Examples.CSharpExecutionDependentGroupsExample.Test6

Summary: Total=9, Passed=6, Failed=2, Blocked=1, Not Run=0, Skipped=0

テストの実行順序が想定どおりであることに注意してください。