File tree 2 files changed +19
-7
lines changed
2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,9 @@ public class Class1
10
10
{
11
11
public int addFlaky ( int x , int y )
12
12
{
13
-
14
- //compute the actual sum.
13
+ // Here, this business logic itself is flaky.
14
+ //
15
+ // compute the actual sum.
15
16
// then genereate a random number below 1000. If that number is odd, then add 1 to the sum.
16
17
// return the sum
17
18
int sum = x + y ;
@@ -23,7 +24,7 @@ public int addFlaky(int x, int y)
23
24
return sum ;
24
25
}
25
26
26
- public int add ( int x , int y )
27
+ public int addStable ( int x , int y )
27
28
{
28
29
int sum = x + y ;
29
30
return sum ;
Original file line number Diff line number Diff line change @@ -6,27 +6,38 @@ namespace AppTestProject1
6
6
[ TestClass ]
7
7
public class UnitTest1
8
8
{
9
+ // ------------------------
10
+ // Flaky SUT business logic
11
+ // ------------------------
9
12
[ TestMethod ]
10
13
public void TestIsFlakyCozSUTisFalky ( )
11
14
{
12
- // this test is flaky because the SUT is flaky.
15
+ // this test is flaky because the SUT business logic is flaky.
13
16
int x = 3 ;
14
17
int y = 4 ;
15
18
int sum = 7 ;
16
-
17
19
int val = new AppCode . Class1 ( ) . addFlaky ( x , y ) ;
18
20
Assert . AreEqual ( sum , val ) ;
19
21
}
20
22
21
- private static int state = new System . Random ( ) . Next ( 2 ) ;
23
+ // ------------------------
24
+ // Flaky environment
25
+ // ------------------------
26
+ private static int state = new System . Random ( ) . Next ( 2 ) ; // simulate a flaky environment.
22
27
23
28
[ TestMethod ]
24
29
public void TestIsFlakyCozEnvIsFlaky ( )
25
30
{
26
31
// this test is flaky because the environment is flaky
27
- Assert . AreEqual ( state , 0 ) ;
32
+ int val = state ;
33
+ Assert . AreEqual ( val , 0 ) ;
28
34
}
29
35
36
+
37
+ // -----------------------------------------------------
38
+ // Flaky due to dependence on execution order
39
+ // This a varition of the case of the flaky environment.
40
+ // -----------------------------------------------------
30
41
private static bool parentRan = false ;
31
42
32
43
[ TestMethod ]
You can’t perform that action at this time.
0 commit comments