실행 그룹

이 섹션을 진행하기 전에 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가 실행됩니다. 마찬가지로 Test2가 성공적으로 실행되고 통과하는 경우에만 Test3이 실행됩니다.

Test2가 실패하도록 디자인된 것을 볼 수 있습니다(위의 줄 14 및 15 참조).

"DependentTests" "ExecutionGroup"에서 Test2가 실패하므로 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만 실행하려고 하면 Test2가 Test1에 종속되어 동일한 ExecutionGroup의 일부이므로 차단됩니다.

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으로 간주됩니다.

또한 메시지는 Test3이 Test2와 동일한 환경에서 실행되어야 한다고 말합니다. 이 측면을 좀 더 자세히 이해해 보겠습니다. ExecutionGroup의 일부가 된다는 것은 실제로 시나리오 기반 테스트의 일부가 된다는 것을 의미하므로 모든 테스트가 요청되므로 동일한 환경에서 실행되는 것이 중요합니다. instance 경우 스레딩 모델이 ExecutionGroup 내에서 변경되면 차단된 테스트가 표시됩니다. 예를 들어 위의 예제에서 Test2가 성공적으로 실행되도록 설계되었지만 'ThreadingModel' 속성이 'MTA'로 설정된 경우 Test3은 여전히 차단됩니다.

예제\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개의 다른 실행 그룹이 있습니다.

  • "첫 번째 실행 그룹"에는 Test1, Test2; 둘 다 성공적으로 통과해야 합니다.
  • "두 번째 실행 그룹"에는 Test3 및 Test4가 포함됩니다. Test4는 이 ExecutionGroup의 마지막 테스트이며 실패합니다.
  • "세 번째 실행 그룹"에는 Test5, Test6 및 Test7이 포함됩니다. 이전 ExecutionGroup의 Test4가 실패했지만 Test5가 성공적으로 실행되고 통과합니다. Test6은 실패하도록 설계되어 Test7이 차단됩니다.
  • "네 번째 실행 그룹"에는 Test8 및 Test9가 포함됩니다. 다시 한 번 이전 ExecutionGroup의 Test7이 Test6 실패로 인해 차단되었지만 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

테스트 실행 순서는 예상대로입니다.