Aracılığıyla paylaş


Yürütme Grupları

Bu bölüme geçmeden önce lütfen TAEF'in temel yürütmesini bildiğinizden ve testleri kullanarak nasıl Yazabileceğinizi bildiğinizden emin olun. Ayrıca, Kullanıcı Kılavuzu'nda listelenen bazı veri temelli test örneği kılavuzuna da göz atabilirsiniz.

TAEF ileScenario-Based Testi

Senaryo düzeyinde testlerden bahsederken, bir sonraki testin yürütülmesinin ancak senaryodaki bir önceki testin başarılı olması durumunda anlamlı olduğu bir dizi testten bahsediyorsunuz. Bazı durumlarda, önceki test başarısız olursa sonraki testi yürütmek için ihtiyacınız olan tüm bilgilere sahip olmayabilirsiniz. Bu sona doğru, yürütme birimini bir test yöntemi olarak tutarken ve test senaryolarına izin verirken, TAEF "ExecutionGroup" olarak bilinenleri destekler. Veri temelli test gibi diğer özelliklere sahip olmanıza rağmen TAEF'de senaryo tabanlı testlere sahip olabilirsiniz. Senaryonuzu veri temelli testden yararlanacak şekilde tasarlarsanız, TAEF tarafından sunulan Veri temelli sınıf işlevselliğini kullanarak sınıf düzeyinde veri temelli destek uygulayabilirsiniz. Veri temelli desteği sınıf düzeyinde uygulayarak, sınıfınızdaki tüm testlerin her satır için sırayla yürütülmesini sağlayabilirsiniz.

Bu sayfa, sınıfın içindeki bir test dizisinin "ExecutionGroup" olarak nasıl belirtileceğine odaklanacaktır.

Yürütme Grupları

Yürütme Gruplarını tartışmadan önce, TAEF'de bir sınıf içindeki testlerin yürütülme sırasının, yerel kod durumunda bunları bir TEST_METHOD(...) olarak nitelediğiniz veya yönetilen kod durumunda yöntemin önüne [TestMethod] özelliği eklediğiniz sıra olduğunu unutmayın ve unutmayın. TAEF sınıfların kendilerini çalışma sırasını garanti etmez.

Senaryo tabanlı testlerde yalnızca yürütme sırasını garanti etmek yeterli olmayabilir. Ayrıca, senaryodaki bir sonraki teste geçmeden önce senaryodaki önceki tüm testlerin başarılı olduğunu da garanti etmeniz gerekir. Burada "ExecutionGroup" kavramının yararlı olacağını göreceksiniz.

Yerel bir örneği göz önünde bulundurun:

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    };

Yukarıdaki C++ dosya parçacığında 4. satıra bakın. Bu özel durumda, ExecutionDependencyExample sınıfındaki tüm testleri "DependentTests" adlı bir "Yürütme Grubu"na ait olacak şekilde belirliyorsunuz. Bu, "Test1", "Test2" ve "Test3" değerlerinin "DependentTests" yürütme grubunun bir parçası olduğu anlamına gelir. "Söylendiği gibi, Test2 yalnızca Test1 başarıyla yürütülür ve geçerse çalıştırılır." Ancak ve ancak Test2 başarıyla yürütülür ve geçerse Test3 yürütülür.

Test2'nin başarısız olacak şekilde tasarlandığını göreceksiniz (yukarıdaki 14 ve 15. satırlara bakın).

"DependentTests" "ExecutionGroup" içinde Test2 başarısız olduğundan Test3 yürütülmeyecek ve bunun yerine engellenmiş olarak işaretlenecektir. Yukarıdaki testi çalıştırmayı deneyelim ve bunun gerçekten doğru olup olmadığını görelim.

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

Tahmin edildiği gibi Test1'in geçtiğine, Test2'nin başarısız olduğuna ve Test3'in engellendiğine dikkat edin. Test3 ile TAEF, Test3'in bir yürütme grubuna ait olduğunu ve önceki testin başarıyla yürütülmediğini belirten bir iletiyi günlüğe kaydeder.

Bu hata iletisi, geçerli test yürütülmeden önce aynı ExecutionGroup'a ait olan tüm testlerin seçilmesi gerektiğini de belirtir. Başka bir deyişle, çalışma zamanında bir seçim ölçütü kullanarak yalnızca Test2 çalıştırmayı denerseniz, aynı ExecutionGroup'un parçası olan Test1'e bağlı olarak Test2'nin engellendiğini göreceksiniz.

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

Ancak, ExecutionGroup'taki ilk test olan Test1'i seçerseniz, başarıyla çalıştırılır.

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

Ayrıca, ExecutionGroup'a ait olmayan testleriniz varsa, ExecutionGroup içindeki testlerin yürütme sonucuna bakılmaksızın yürütülürler. Bir sınıfta birden fazla ExecutionGroup olması da mümkündür. Ancak ExecutionGroup'un Sınıflar arasında yayılamayacağını unutmayın. Bunu yaparsanız, bunlar her sınıfta bir tane olmak üzere iki ayrı ExecutionGroup olarak kabul edilir.

İleti, Test3'in Test2 ile aynı ortamda çalıştırılması gerektiğini de söyler. Şimdi bu yönü biraz daha ayrıntılı olarak anlamaya çalışalım. ExecutionGroup'un bir parçası olmak aslında senaryo tabanlı testin bir parçası olmak anlamına geldiğinden, tüm testlerin talep etmesi ve dolayısıyla aynı ortamda gerçekleştirilmesi büyük önem taşır. Örneğin, bir ExecutionGroup içinde İş Parçacığı Modeli değiştiğinde, engellenen testleri görebilirsiniz. Örneğin, yukarıdaki örnekte Test2 başarıyla yürütülecek şekilde tasarlandıysa ancak 'ThreadingModel' özelliği 'MTA' olarak ayarlandıysa, Test3 yine de engellenir.

Başka bir örnek düşünelim: Examples\TAEF\CSharp\ExecutionDependentGroupsExample (lütfen en son TAEF sürüm paylaşımına bakın)

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    }

Bu örnekte 4 farklı yürütme grubu vardır:

  • "İlk Yürütme Grubu" Test1, Test2 içerir; her ikisi de başarıyla geçmelidir.
  • "İkinci Yürütme Grubu" Test3 ve Test4 içerir. Test4, bu ExecutionGroup'taki son testtir ve başarısız olur.
  • "Üçüncü Yürütme Grubu" Test5, Test6 ve Test7'yi içerir. Önceki ExecutionGroup'tan Test4 başarısız olmasına rağmen Test5 başarıyla yürütülür ve geçer. Test6 başarısız olacak şekilde tasarlanmıştır, bu da Test7'nin Engellenmesine neden olur.
  • "Dördüncü Yürütme Grubu" Test8 ve Test9'u içerir. Bir kez daha, Test6 başarısız olduğundan önceki ExecutionGroup'tan Test7 Engellendi olsa da, Test8 başarıyla yürütülür ve Test9 da yürütülür.

Bu örnekteki ExecutionGroup'ları daha iyi anlamak için bu örnekteki özellikleri listeleyelim.

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

Yukarıdaki testi yürütürken, aşağıdaki çıkış tahmin edilen yürütme sırasını onaylar.

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

Test yürütme sırasının beklendiği gibi olduğuna dikkat edin.