asunit4 4.2.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -0
- data/MIT-LICENSE.txt +22 -0
- data/README.textile +6 -0
- data/air/AIR2Runner.mxml +22 -0
- data/air/AIR2RunnerDescriptor.xml +38 -0
- data/asunit4.gemspec +20 -0
- data/asunit4.rb +16 -0
- data/bin/AsUnit-4.1.pre.swc +0 -0
- data/bin/AsUnitRunner.swf +0 -0
- data/build.xml +46 -0
- data/lib/Reflection.swc +0 -0
- data/rakefile.rb +169 -0
- data/script/generate +21 -0
- data/src/asunit/asserts/assertEquals.as +5 -0
- data/src/asunit/asserts/assertEqualsArrays.as +5 -0
- data/src/asunit/asserts/assertEqualsArraysIgnoringOrder.as +5 -0
- data/src/asunit/asserts/assertEqualsFloat.as +5 -0
- data/src/asunit/asserts/assertFalse.as +5 -0
- data/src/asunit/asserts/assertNotNull.as +5 -0
- data/src/asunit/asserts/assertNotSame.as +5 -0
- data/src/asunit/asserts/assertNull.as +5 -0
- data/src/asunit/asserts/assertSame.as +5 -0
- data/src/asunit/asserts/assertThrows.as +5 -0
- data/src/asunit/asserts/assertTrue.as +5 -0
- data/src/asunit/asserts/fail.as +5 -0
- data/src/asunit/core/AsUnitCore.as +177 -0
- data/src/asunit/core/FlashBuilderCore.as +22 -0
- data/src/asunit/core/FlashDevelopCore.as +21 -0
- data/src/asunit/core/TextCore.as +54 -0
- data/src/asunit/errors/AbstractError.as +10 -0
- data/src/asunit/errors/AssertionFailedError.as +10 -0
- data/src/asunit/errors/ClassNotFoundError.as +11 -0
- data/src/asunit/errors/InstanceNotFoundError.as +10 -0
- data/src/asunit/errors/UnimplementedFeatureError.as +10 -0
- data/src/asunit/errors/UsageError.as +11 -0
- data/src/asunit/events/TimeoutCommandEvent.as +27 -0
- data/src/asunit/framework/Assert.as +408 -0
- data/src/asunit/framework/Async.as +138 -0
- data/src/asunit/framework/CallbackBridge.as +175 -0
- data/src/asunit/framework/Command.as +6 -0
- data/src/asunit/framework/ErrorEvent.as +20 -0
- data/src/asunit/framework/IAsync.as +21 -0
- data/src/asunit/framework/IResult.as +36 -0
- data/src/asunit/framework/IRunListener.as +11 -0
- data/src/asunit/framework/IRunner.as +15 -0
- data/src/asunit/framework/IRunnerFactory.as +9 -0
- data/src/asunit/framework/ITestFailure.as +32 -0
- data/src/asunit/framework/ITestListener.as +15 -0
- data/src/asunit/framework/ITestResult.as +21 -0
- data/src/asunit/framework/ITestSuccess.as +22 -0
- data/src/asunit/framework/ITestWarning.as +14 -0
- data/src/asunit/framework/InjectionDelegate.as +96 -0
- data/src/asunit/framework/LegacyTestIterator.as +40 -0
- data/src/asunit/framework/MessageBridge.as +24 -0
- data/src/asunit/framework/Method.as +80 -0
- data/src/asunit/framework/Result.as +181 -0
- data/src/asunit/framework/RunnerFactory.as +179 -0
- data/src/asunit/framework/SuiteIterator.as +71 -0
- data/src/asunit/framework/TestCase.as +106 -0
- data/src/asunit/framework/TestFailure.as +65 -0
- data/src/asunit/framework/TestIterator.as +282 -0
- data/src/asunit/framework/TestObserver.as +12 -0
- data/src/asunit/framework/TestSuccess.as +38 -0
- data/src/asunit/framework/TestWarning.as +40 -0
- data/src/asunit/framework/TimeoutCommand.as +103 -0
- data/src/asunit/printers/FlashBuilderPrinter.as +134 -0
- data/src/asunit/printers/FlashDevelopPrinter.as +81 -0
- data/src/asunit/printers/TextPrinter.as +324 -0
- data/src/asunit/runners/LegacyRunner.as +13 -0
- data/src/asunit/runners/SuiteRunner.as +125 -0
- data/src/asunit/runners/TestRunner.as +403 -0
- data/src/asunit/util/ArrayIterator.as +30 -0
- data/src/asunit/util/Iterator.as +10 -0
- data/test/AllTests.as +73 -0
- data/test/AsUnitRunner.as +15 -0
- data/test/Flex3Runner.mxml +24 -0
- data/test/Flex4Runner.mxml +27 -0
- data/test/asunit/core/AsUnitCoreTest.as +97 -0
- data/test/asunit/framework/AssertEqualsArraysIgnoringOrderTest.as +88 -0
- data/test/asunit/framework/AssertEqualsArraysTest.as +102 -0
- data/test/asunit/framework/AssertTest.as +184 -0
- data/test/asunit/framework/AssertThrowsTest.as +42 -0
- data/test/asunit/framework/AsyncMethodTest.as +69 -0
- data/test/asunit/framework/AsyncTest.as +104 -0
- data/test/asunit/framework/CallbackBridgeTest.as +73 -0
- data/test/asunit/framework/InjectionDelegateTest.as +79 -0
- data/test/asunit/framework/MockData.xml +8 -0
- data/test/asunit/framework/NestedSuiteIteratorTest.as +59 -0
- data/test/asunit/framework/ProceedOnEventTest.as +109 -0
- data/test/asunit/framework/ResultTest.as +92 -0
- data/test/asunit/framework/RunnerFactoryTest.as +54 -0
- data/test/asunit/framework/SuiteIteratorTest.as +67 -0
- data/test/asunit/framework/TestCaseMock.as +24 -0
- data/test/asunit/framework/TestIteratorIgnoredMethodTest.as +62 -0
- data/test/asunit/framework/TestIteratorMethodByNameTest.as +50 -0
- data/test/asunit/framework/TestIteratorMultiMethodTest.as +186 -0
- data/test/asunit/framework/TestIteratorOrderedTestMethodTest.as +57 -0
- data/test/asunit/framework/TestIteratorSingleMethodTest.as +56 -0
- data/test/asunit/framework/VisualTestCaseTest.as +43 -0
- data/test/asunit/framework/assertAssertionFailed.as +19 -0
- data/test/asunit/printers/TextPrinterTest.as +122 -0
- data/test/asunit/runners/LegacyRunnerTest.as +40 -0
- data/test/asunit/runners/SuiteRunnerTest.as +40 -0
- data/test/asunit/runners/TestRunnerAsyncMethodTest.as +107 -0
- data/test/asunit/runners/TestRunnerErrorMethodTest.as +56 -0
- data/test/asunit/runners/TestRunnerExpectsErrorTest.as +98 -0
- data/test/asunit/runners/TestRunnerIgnoredMethodTest.as +42 -0
- data/test/asunit/runners/TestRunnerTest.as +171 -0
- data/test/asunit/support/AnnotatedSubClass.as +18 -0
- data/test/asunit/support/AnnotatedSuperClass.as +15 -0
- data/test/asunit/support/CustomParameters.as +13 -0
- data/test/asunit/support/CustomTestRunner.as +22 -0
- data/test/asunit/support/DoubleFailSuite.as +8 -0
- data/test/asunit/support/DoubleNestedSuite.as +14 -0
- data/test/asunit/support/ErrorInMethod.as +11 -0
- data/test/asunit/support/FailAssertEquals.as +29 -0
- data/test/asunit/support/FailAssertTrue.as +28 -0
- data/test/asunit/support/FakeObserver.as +42 -0
- data/test/asunit/support/FakeRunner.as +32 -0
- data/test/asunit/support/IgnoredMethod.as +26 -0
- data/test/asunit/support/InjectTimeoutOnAsync.as +14 -0
- data/test/asunit/support/InjectionFailure.as +18 -0
- data/test/asunit/support/InjectionVerification.as +69 -0
- data/test/asunit/support/LegacyTestCase.as +38 -0
- data/test/asunit/support/MultiMethod.as +77 -0
- data/test/asunit/support/OrderedTestMethod.as +36 -0
- data/test/asunit/support/RunWithButNoType.as +14 -0
- data/test/asunit/support/RunWithSuiteButNoType.as +11 -0
- data/test/asunit/support/SingleErrorSuite.as +7 -0
- data/test/asunit/support/SingleSuccessSuite.as +7 -0
- data/test/asunit/support/SucceedAssertTrue.as +31 -0
- data/test/asunit/support/SuiteOfTwoSuites.as +8 -0
- data/test/asunit/support/SuiteWithCustomRunner.as +12 -0
- data/test/asunit/support/SuiteWithOneCustomChildSuite.as +10 -0
- data/test/asunit/support/TestForFakeRunner.as +14 -0
- data/test/asunit/util/ArrayIteratorTest.as +65 -0
- data/vendor/as3reflection/README +7 -0
- data/vendor/as3reflection/p2/reflect/Reflection.as +417 -0
- data/vendor/as3reflection/p2/reflect/ReflectionAccessor.as +14 -0
- data/vendor/as3reflection/p2/reflect/ReflectionBase.as +52 -0
- data/vendor/as3reflection/p2/reflect/ReflectionMember.as +16 -0
- data/vendor/as3reflection/p2/reflect/ReflectionMetaData.as +69 -0
- data/vendor/as3reflection/p2/reflect/ReflectionMethod.as +36 -0
- data/vendor/as3reflection/p2/reflect/ReflectionMethodParameter.as +19 -0
- data/vendor/as3reflection/p2/reflect/ReflectionVariable.as +15 -0
- data/vendor/as3reflection/p2/reflect/findFirst.as +14 -0
- data/vendor/generators/suite/USAGE +0 -0
- data/vendor/generators/suite/suite_generator.rb +17 -0
- data/vendor/generators/suite/templates/TestSuite.as +17 -0
- metadata +216 -0
@@ -0,0 +1,186 @@
|
|
1
|
+
package asunit.framework {
|
2
|
+
|
3
|
+
import asunit.framework.TestCase;
|
4
|
+
import asunit.util.ArrayIterator;
|
5
|
+
import asunit.util.Iterator;
|
6
|
+
|
7
|
+
import asunit.support.MultiMethod;
|
8
|
+
|
9
|
+
public class TestIteratorMultiMethodTest extends TestCase {
|
10
|
+
|
11
|
+
private var multiTest:MultiMethod;
|
12
|
+
|
13
|
+
public function TestIteratorMultiMethodTest(testMethod:String = null) {
|
14
|
+
super(testMethod);
|
15
|
+
}
|
16
|
+
|
17
|
+
protected override function setUp():void {
|
18
|
+
super.setUp();
|
19
|
+
multiTest = new MultiMethod();
|
20
|
+
}
|
21
|
+
|
22
|
+
protected override function tearDown():void {
|
23
|
+
super.setUp();
|
24
|
+
multiTest = null;
|
25
|
+
}
|
26
|
+
|
27
|
+
private function verifyMethods(actual:Iterator, expectedItems:Array):void {
|
28
|
+
var expected:Iterator = new ArrayIterator(expectedItems);
|
29
|
+
assertEquals(expected.length, actual.length);
|
30
|
+
var actualMethod:Method;
|
31
|
+
var expectedMethod:Object;
|
32
|
+
for(var i:uint; i < expected.length; i++) {
|
33
|
+
actualMethod = actual.next();
|
34
|
+
expectedMethod = expected.next();
|
35
|
+
assertEquals(expectedMethod.name, actualMethod.name);
|
36
|
+
assertSame(expectedMethod.name + " with wrong value", expectedMethod.value, actualMethod.value);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
public function test_get_BeforeClass_methods_of_test_instance():void {
|
41
|
+
var iterator:Iterator = new TestIterator(multiTest).beforeClassIterator;
|
42
|
+
var methods:Array = [
|
43
|
+
{ name: 'runBeforeClass1', value: MultiMethod.runBeforeClass1 },
|
44
|
+
{ name: 'runBeforeClass2', value: MultiMethod.runBeforeClass2 }
|
45
|
+
];
|
46
|
+
|
47
|
+
verifyMethods(iterator, methods);
|
48
|
+
}
|
49
|
+
|
50
|
+
public function test_get_AfterClass_methods_of_test_instance():void {
|
51
|
+
var iterator:Iterator = new TestIterator(multiTest).afterClassIterator;
|
52
|
+
var methods:Array = [
|
53
|
+
{ name: 'runAfterClass1', value: MultiMethod.runAfterClass1 },
|
54
|
+
{ name: 'runAfterClass2', value: MultiMethod.runAfterClass2 }
|
55
|
+
];
|
56
|
+
|
57
|
+
verifyMethods(iterator, methods);
|
58
|
+
}
|
59
|
+
|
60
|
+
public function test_get_before_methods_of_test_instance():void {
|
61
|
+
var iterator:Iterator = new TestIterator(multiTest).beforeIterator;
|
62
|
+
var methods:Array = [
|
63
|
+
{ name: 'runBefore1', value: multiTest.runBefore1 },
|
64
|
+
{ name: 'runBefore2', value: multiTest.runBefore2 },
|
65
|
+
];
|
66
|
+
|
67
|
+
verifyMethods(iterator, methods);
|
68
|
+
}
|
69
|
+
|
70
|
+
public function test_get_test_methods_of_test_instance():void {
|
71
|
+
//NOTE: Avoid naming variables the same as testMethods property in asunit.framework.TestCase.
|
72
|
+
var iterator:Iterator = new TestIterator(multiTest).testMethodsIterator;
|
73
|
+
var methods:Array = [
|
74
|
+
{ name: 'fail_assertEquals', value: multiTest.fail_assertEquals },
|
75
|
+
{ name: 'numChildren_is_0_by_default', value: multiTest.numChildren_is_0_by_default },
|
76
|
+
{ name: 'stage_is_null_by_default', value: multiTest.stage_is_null_by_default }
|
77
|
+
];
|
78
|
+
|
79
|
+
verifyMethods(iterator, methods);
|
80
|
+
}
|
81
|
+
|
82
|
+
public function test_get_after_methods_of_test_instance():void {
|
83
|
+
var iterator:Iterator = new TestIterator(multiTest).afterIterator;
|
84
|
+
var methods:Array = [
|
85
|
+
{ name: 'runAfter1', value: multiTest.runAfter1 },
|
86
|
+
{ name: 'runAfter2', value: multiTest.runAfter2 }
|
87
|
+
];
|
88
|
+
|
89
|
+
verifyMethods(iterator, methods);
|
90
|
+
}
|
91
|
+
|
92
|
+
public function testIteratorNext():void {
|
93
|
+
var iterator:Iterator = new TestIterator(multiTest); // Use this to ensure we use the Iterator interface
|
94
|
+
var testIterator:TestIterator = iterator as TestIterator; // Use this to check TestIterator interface
|
95
|
+
|
96
|
+
assertTrue('setup a', testIterator.readyToSetUp);
|
97
|
+
assertFalse('teardown a', testIterator.readyToTearDown);
|
98
|
+
assertEquals('runBeforeClass1', iterator.next().name);
|
99
|
+
assertFalse('setup b', testIterator.readyToSetUp);
|
100
|
+
assertFalse('teardown b', testIterator.readyToTearDown);
|
101
|
+
assertEquals('runBeforeClass2', iterator.next().name);
|
102
|
+
|
103
|
+
assertFalse('setup c', testIterator.readyToSetUp);
|
104
|
+
assertFalse('teardown c', testIterator.readyToTearDown);
|
105
|
+
|
106
|
+
assertEquals('runBefore1', iterator.next().name);
|
107
|
+
assertFalse('setup d', testIterator.readyToSetUp);
|
108
|
+
assertFalse('teardown d', testIterator.readyToTearDown);
|
109
|
+
assertFalse('setup e', testIterator.readyToSetUp);
|
110
|
+
assertEquals('runBefore2', iterator.next().name);
|
111
|
+
assertFalse('setup e', testIterator.readyToSetUp);
|
112
|
+
assertFalse('teardown e', testIterator.readyToTearDown);
|
113
|
+
assertEquals('fail_assertEquals', iterator.next().name);
|
114
|
+
assertFalse('setup f', testIterator.readyToSetUp);
|
115
|
+
assertFalse('teardown f', testIterator.readyToTearDown);
|
116
|
+
assertEquals('runAfter1', iterator.next().name);
|
117
|
+
assertFalse('setup g', testIterator.readyToSetUp);
|
118
|
+
assertFalse('teardown g', testIterator.readyToTearDown);
|
119
|
+
assertEquals('runAfter2', iterator.next().name);
|
120
|
+
|
121
|
+
assertTrue('setup h', testIterator.readyToSetUp);
|
122
|
+
assertTrue('teardown h', testIterator.readyToTearDown);
|
123
|
+
|
124
|
+
assertEquals('runBefore1', iterator.next().name);
|
125
|
+
assertFalse('setup i', testIterator.readyToSetUp);
|
126
|
+
assertFalse('teardown i', testIterator.readyToTearDown);
|
127
|
+
assertEquals('runBefore2', iterator.next().name);
|
128
|
+
assertFalse('setup j', testIterator.readyToSetUp);
|
129
|
+
assertFalse('teardown j', testIterator.readyToTearDown);
|
130
|
+
assertEquals('numChildren_is_0_by_default', iterator.next().name);
|
131
|
+
assertFalse('setup k', testIterator.readyToSetUp);
|
132
|
+
assertFalse('teardown k', testIterator.readyToTearDown);
|
133
|
+
assertEquals('runAfter1', iterator.next().name);
|
134
|
+
assertFalse('setup l', testIterator.readyToSetUp);
|
135
|
+
assertFalse('teardown l', testIterator.readyToTearDown);
|
136
|
+
assertEquals('runAfter2', iterator.next().name);
|
137
|
+
|
138
|
+
assertTrue('setup m', testIterator.readyToSetUp);
|
139
|
+
assertTrue('teardown m', testIterator.readyToTearDown);
|
140
|
+
|
141
|
+
assertEquals('runBefore1', iterator.next().name);
|
142
|
+
assertFalse('setup n', testIterator.readyToSetUp);
|
143
|
+
assertFalse('teardown n', testIterator.readyToTearDown);
|
144
|
+
assertEquals('runBefore2', iterator.next().name);
|
145
|
+
assertFalse('setup o', testIterator.readyToSetUp);
|
146
|
+
assertFalse('teardown o', testIterator.readyToTearDown);
|
147
|
+
assertEquals('stage_is_null_by_default', iterator.next().name);
|
148
|
+
assertFalse('setup p', testIterator.readyToSetUp);
|
149
|
+
assertFalse('teardown p', testIterator.readyToTearDown);
|
150
|
+
assertEquals('runAfter1', iterator.next().name);
|
151
|
+
assertFalse('setup q', testIterator.readyToSetUp);
|
152
|
+
assertFalse('teardown q', testIterator.readyToTearDown);
|
153
|
+
assertEquals('runAfter2', iterator.next().name);
|
154
|
+
|
155
|
+
assertFalse('setup r', testIterator.readyToSetUp); // No more setUps remaining!
|
156
|
+
assertTrue('teardown r', testIterator.readyToTearDown);
|
157
|
+
|
158
|
+
assertEquals('runAfterClass1', iterator.next().name);
|
159
|
+
assertFalse('setup s', testIterator.readyToSetUp);
|
160
|
+
assertFalse('teardown s', testIterator.readyToTearDown);
|
161
|
+
assertEquals('runAfterClass2', iterator.next().name);
|
162
|
+
assertFalse('setup t', testIterator.readyToSetUp);
|
163
|
+
assertFalse('teardown t', testIterator.readyToTearDown);
|
164
|
+
|
165
|
+
assertFalse('no methods left in iterator', iterator.hasNext());
|
166
|
+
}
|
167
|
+
|
168
|
+
public function testIteratorExhaustedWithWhileLoopThenResetShouldHasNext():void {
|
169
|
+
var iterator:Iterator = new TestIterator(multiTest);
|
170
|
+
while(iterator.hasNext()) {
|
171
|
+
iterator.next();
|
172
|
+
}
|
173
|
+
iterator.reset();
|
174
|
+
|
175
|
+
assertTrue(iterator.hasNext());
|
176
|
+
}
|
177
|
+
|
178
|
+
public function testIteratorLength():void {
|
179
|
+
// TestIterator.length reflects all methods that will be called...
|
180
|
+
// not just test methods and not all non-test methods * test methods.
|
181
|
+
var iterator:TestIterator = new TestIterator(multiTest);
|
182
|
+
assertEquals(19, iterator.length);
|
183
|
+
}
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
package asunit.framework {
|
2
|
+
|
3
|
+
import asunit.framework.TestCase;
|
4
|
+
import asunit.util.Iterator;
|
5
|
+
|
6
|
+
import asunit.support.OrderedTestMethod;
|
7
|
+
|
8
|
+
public class TestIteratorOrderedTestMethodTest extends TestCase {
|
9
|
+
|
10
|
+
private var iterator:Iterator;
|
11
|
+
private var orderedTest:OrderedTestMethod;
|
12
|
+
|
13
|
+
public function TestIteratorOrderedTestMethodTest(testMethod:String = null) {
|
14
|
+
super(testMethod);
|
15
|
+
}
|
16
|
+
|
17
|
+
protected override function setUp():void {
|
18
|
+
super.setUp();
|
19
|
+
orderedTest = new OrderedTestMethod();
|
20
|
+
}
|
21
|
+
|
22
|
+
protected override function tearDown():void {
|
23
|
+
super.tearDown();
|
24
|
+
iterator = null;
|
25
|
+
orderedTest = null;
|
26
|
+
}
|
27
|
+
|
28
|
+
public function test_countTestMethods_of_test():void {
|
29
|
+
iterator = new TestIterator(orderedTest);
|
30
|
+
assertEquals(4, iterator.length);
|
31
|
+
}
|
32
|
+
|
33
|
+
public function test_get_test_methods_of_test_instance():void {
|
34
|
+
//NOTE: Avoid naming variables the same as testMethods property in asunit.framework.TestCase.
|
35
|
+
var iterator:Iterator = new TestIterator(orderedTest);
|
36
|
+
|
37
|
+
assertEquals(4, iterator.length);
|
38
|
+
var first:Method = iterator.next();
|
39
|
+
var second:Method = iterator.next();
|
40
|
+
var third:Method = iterator.next();
|
41
|
+
var fourth:Method = iterator.next();
|
42
|
+
|
43
|
+
assertFalse("Should be out of items", iterator.next());
|
44
|
+
|
45
|
+
assertEquals(first.name, 'negativeOrderIsAllowed');
|
46
|
+
assertEquals(second.name, 'zeroIsDefaultOrder');
|
47
|
+
assertEquals(third.name, 'two');
|
48
|
+
assertEquals(fourth.name, 'three');
|
49
|
+
|
50
|
+
assertEquals(orderedTest.negativeOrderIsAllowed, first.value);
|
51
|
+
assertEquals(orderedTest.zeroIsDefaultOrder, second.value);
|
52
|
+
assertEquals(orderedTest.two, third.value);
|
53
|
+
assertEquals(orderedTest.three, fourth.value);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
package asunit.framework {
|
2
|
+
|
3
|
+
import asunit.framework.TestCase;
|
4
|
+
import asunit.util.Iterator;
|
5
|
+
|
6
|
+
import asunit.support.FailAssertTrue;
|
7
|
+
|
8
|
+
public class TestIteratorSingleMethodTest extends TestCase {
|
9
|
+
|
10
|
+
private var iterator:Iterator;
|
11
|
+
private var singleTest:FailAssertTrue;
|
12
|
+
|
13
|
+
public function TestIteratorSingleMethodTest(testMethod:String = null) {
|
14
|
+
super(testMethod);
|
15
|
+
}
|
16
|
+
|
17
|
+
protected override function setUp():void {
|
18
|
+
super.setUp();
|
19
|
+
singleTest = new FailAssertTrue();
|
20
|
+
}
|
21
|
+
|
22
|
+
protected override function tearDown():void {
|
23
|
+
super.tearDown();
|
24
|
+
iterator = null;
|
25
|
+
singleTest = null;
|
26
|
+
}
|
27
|
+
|
28
|
+
public function test_iterator_for_null_yields_hasNext_false():void {
|
29
|
+
iterator = new TestIterator(null);
|
30
|
+
assertFalse(iterator.hasNext());
|
31
|
+
}
|
32
|
+
|
33
|
+
public function test_iterator_for_non_test_yields_hasNext_false():void {
|
34
|
+
iterator = new TestIterator(new Date());
|
35
|
+
assertFalse(iterator.hasNext());
|
36
|
+
}
|
37
|
+
|
38
|
+
public function test_iterator_for_test_with_one_test_method_hasNext():void {
|
39
|
+
iterator = new TestIterator(singleTest);
|
40
|
+
assertTrue(iterator.hasNext());
|
41
|
+
}
|
42
|
+
|
43
|
+
public function test_iterator_next():void {
|
44
|
+
iterator = new TestIterator(singleTest);
|
45
|
+
|
46
|
+
assertTrue('a', iterator.hasNext());
|
47
|
+
assertEquals('runBefore', iterator.next().toString());
|
48
|
+
assertTrue('b', iterator.hasNext());
|
49
|
+
assertEquals('fail_assertTrue', iterator.next().toString());
|
50
|
+
assertTrue('c', iterator.hasNext());
|
51
|
+
assertEquals('runAfter', iterator.next().toString());
|
52
|
+
assertFalse('no methods left in iterator', iterator.hasNext());
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
package asunit.framework {
|
2
|
+
|
3
|
+
import asunit.asserts.*;
|
4
|
+
|
5
|
+
import flash.display.Sprite;
|
6
|
+
|
7
|
+
public class VisualTestCaseTest {
|
8
|
+
|
9
|
+
[Inject]
|
10
|
+
public var sprite:Sprite;
|
11
|
+
|
12
|
+
[Test]
|
13
|
+
public function instantiated():void {
|
14
|
+
assertTrue(sprite is Sprite);
|
15
|
+
}
|
16
|
+
|
17
|
+
[Test]
|
18
|
+
public function testSize():void {
|
19
|
+
assertTrue(sprite.width == 0);
|
20
|
+
assertTrue(sprite.height == 0);
|
21
|
+
}
|
22
|
+
|
23
|
+
[Test]
|
24
|
+
public function testDrawnSize():void {
|
25
|
+
sprite.x = 110;
|
26
|
+
sprite.y = 115;
|
27
|
+
sprite.graphics.beginFill(0xFF0000);
|
28
|
+
sprite.graphics.drawRect(0, 0, 100, 200);
|
29
|
+
|
30
|
+
assertEquals(100, sprite.width);
|
31
|
+
assertEquals(200, sprite.height);
|
32
|
+
assertEquals(110, sprite.x);
|
33
|
+
assertEquals(115, sprite.y);
|
34
|
+
}
|
35
|
+
|
36
|
+
[Test]
|
37
|
+
public function testSecondSize():void {
|
38
|
+
assertTrue(sprite.width == 0);
|
39
|
+
assertTrue(sprite.height == 0);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
package asunit.framework
|
2
|
+
{
|
3
|
+
import asunit.errors.AssertionFailedError;
|
4
|
+
import asunit.framework.Assert;
|
5
|
+
|
6
|
+
internal function assertAssertionFailed(assertFunction:Function, expected:Object, actual:Object):void {
|
7
|
+
var succeeded:Boolean = false;
|
8
|
+
try {
|
9
|
+
assertFunction.apply(null, [expected, actual]);
|
10
|
+
succeeded = true;
|
11
|
+
}
|
12
|
+
catch (e:AssertionFailedError) {
|
13
|
+
// expected
|
14
|
+
}
|
15
|
+
if (succeeded) {
|
16
|
+
Assert.fail("expected AssertionFailedError");
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
@@ -0,0 +1,122 @@
|
|
1
|
+
package asunit.printers {
|
2
|
+
|
3
|
+
import asunit.framework.ITestFailure;
|
4
|
+
import asunit.framework.TestCase;
|
5
|
+
|
6
|
+
import asunit.framework.IResult;
|
7
|
+
import asunit.framework.ITestSuccess;
|
8
|
+
import asunit.framework.ITestWarning;
|
9
|
+
import asunit.framework.Result;
|
10
|
+
import asunit.framework.TestFailure;
|
11
|
+
import asunit.framework.TestSuccess;
|
12
|
+
import asunit.framework.TestWarning;
|
13
|
+
|
14
|
+
public class TextPrinterTest extends TestCase {
|
15
|
+
|
16
|
+
private var printer:FakeTextPrinter;
|
17
|
+
private var test:*;
|
18
|
+
private var success:ITestSuccess;
|
19
|
+
private var failure:ITestFailure;
|
20
|
+
private var testResult:IResult;
|
21
|
+
|
22
|
+
public function TextPrinterTest(method:String=null) {
|
23
|
+
super(method);
|
24
|
+
}
|
25
|
+
|
26
|
+
override protected function setUp():void {
|
27
|
+
super.setUp();
|
28
|
+
printer = new FakeTextPrinter();
|
29
|
+
printer.backgroundColor = 0xffcc00;
|
30
|
+
printer.textColor = 0x000000;
|
31
|
+
|
32
|
+
testResult = new Result();
|
33
|
+
test = new TestCase();
|
34
|
+
failure = new TestFailure(test, 'testSomethingThatFails', new Error('Fake Failure'));
|
35
|
+
success = new TestSuccess(test, 'testSomethingThatSucceeds');
|
36
|
+
testResult.addListener(printer);
|
37
|
+
}
|
38
|
+
|
39
|
+
override protected function tearDown():void {
|
40
|
+
super.tearDown();
|
41
|
+
removeChild(printer);
|
42
|
+
failure = null;
|
43
|
+
printer = null;
|
44
|
+
testResult = null;
|
45
|
+
success = null;
|
46
|
+
test = null;
|
47
|
+
}
|
48
|
+
|
49
|
+
private function executeASucceedingTest():void {
|
50
|
+
testResult.onRunStarted();
|
51
|
+
testResult.onTestStarted(test);
|
52
|
+
testResult.onTestSuccess(success);
|
53
|
+
testResult.onTestCompleted(test);
|
54
|
+
testResult.onRunCompleted(null);
|
55
|
+
}
|
56
|
+
|
57
|
+
private function executeASucceedingTestWithWarning(warning:ITestWarning):void {
|
58
|
+
testResult.onRunStarted();
|
59
|
+
testResult.onTestStarted(test);
|
60
|
+
testResult.onWarning(warning);
|
61
|
+
testResult.onTestSuccess(success);
|
62
|
+
testResult.onTestCompleted(test);
|
63
|
+
testResult.onRunCompleted(null);
|
64
|
+
}
|
65
|
+
|
66
|
+
private function executeAFailingTest():void {
|
67
|
+
testResult.onRunStarted();
|
68
|
+
testResult.onTestStarted(test);
|
69
|
+
testResult.onTestFailure(failure);
|
70
|
+
testResult.onTestCompleted(test);
|
71
|
+
testResult.onRunCompleted(null);
|
72
|
+
}
|
73
|
+
|
74
|
+
public function testPrinterOnTestSuccess():void {
|
75
|
+
executeASucceedingTest();
|
76
|
+
var actual:String = printer.toString();
|
77
|
+
assertTrue("Printer should print OK", actual.indexOf('OK') > -1);
|
78
|
+
assertTrue("Printer should include Test count: ", actual.match(/\nOK \(1 test\)/));
|
79
|
+
}
|
80
|
+
|
81
|
+
public function testPrinterFailure():void {
|
82
|
+
executeAFailingTest();
|
83
|
+
var expected:String = "testSomethingThatFails : Error: Fake Failure";
|
84
|
+
var actual:String = printer.toString();
|
85
|
+
assertTrue("Printer should fail", actual.indexOf(expected) > -1);
|
86
|
+
assertTrue("Printer should include Test Duration: ", actual.match(/\nTotal Time: \d/));
|
87
|
+
}
|
88
|
+
|
89
|
+
public function testPrinterWithNoTests():void {
|
90
|
+
testResult.onRunStarted();
|
91
|
+
testResult.onRunCompleted(null);
|
92
|
+
assertTrue("Printer should include Warning for no tests", printer.toString().indexOf("[WARNING]") > -1);
|
93
|
+
}
|
94
|
+
|
95
|
+
public function testPrinterDisplayed():void {
|
96
|
+
addChild(printer);
|
97
|
+
executeASucceedingTest();
|
98
|
+
assertTrue("The output was displayed.", printer.getTextDisplay().text.indexOf('Time Summary:') > -1);
|
99
|
+
}
|
100
|
+
|
101
|
+
public function testDisplaysWarnings():void {
|
102
|
+
var message:String = "problem"
|
103
|
+
executeASucceedingTestWithWarning(new TestWarning(message));
|
104
|
+
assertTrue("Printer displays warnings", printer.toString().indexOf(message) > -1);
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
import asunit.printers.TextPrinter;
|
110
|
+
import flash.text.TextField;
|
111
|
+
|
112
|
+
class FakeTextPrinter extends TextPrinter {
|
113
|
+
|
114
|
+
// Prevent the printer from tracing results:
|
115
|
+
override protected function logResult():void {
|
116
|
+
}
|
117
|
+
|
118
|
+
public function getTextDisplay():TextField {
|
119
|
+
return textDisplay;
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
package asunit.runners {
|
2
|
+
|
3
|
+
import asunit.framework.IResult;
|
4
|
+
import asunit.framework.LegacyTestIterator;
|
5
|
+
import asunit.framework.Result;
|
6
|
+
import asunit.framework.TestCase;
|
7
|
+
import asunit.support.LegacyTestCase;
|
8
|
+
|
9
|
+
import flash.events.Event;
|
10
|
+
import asunit.framework.CallbackBridge;
|
11
|
+
|
12
|
+
public class LegacyRunnerTest extends TestCase {
|
13
|
+
|
14
|
+
private var testRunner:LegacyRunner;
|
15
|
+
|
16
|
+
public function LegacyRunnerTest(methodName:String=null) {
|
17
|
+
super(methodName)
|
18
|
+
}
|
19
|
+
|
20
|
+
override protected function setUp():void {
|
21
|
+
super.setUp();
|
22
|
+
LegacyTestCase.callCount = 0;
|
23
|
+
testRunner = new LegacyRunner();
|
24
|
+
}
|
25
|
+
|
26
|
+
override protected function tearDown():void {
|
27
|
+
super.tearDown();
|
28
|
+
testRunner = null;
|
29
|
+
}
|
30
|
+
|
31
|
+
public function testSimpleSubclass():void {
|
32
|
+
var handler:Function = function(event:Event):void {
|
33
|
+
assertEquals(0, testRunner.bridge.failureCount);
|
34
|
+
assertEquals(2, testRunner.bridge.runCount);
|
35
|
+
};
|
36
|
+
testRunner.addEventListener(Event.COMPLETE, addAsync(handler));
|
37
|
+
testRunner.run(LegacyTestCase);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
package asunit.runners {
|
2
|
+
|
3
|
+
import asunit.asserts.*;
|
4
|
+
import asunit.framework.IAsync;
|
5
|
+
import asunit.framework.Result;
|
6
|
+
import asunit.support.DoubleFailSuite;
|
7
|
+
import asunit.support.InjectionVerification;
|
8
|
+
|
9
|
+
import flash.events.Event;
|
10
|
+
|
11
|
+
public class SuiteRunnerTest {
|
12
|
+
|
13
|
+
[Inject]
|
14
|
+
public var async:IAsync;
|
15
|
+
|
16
|
+
[Inject]
|
17
|
+
public var suiteRunner:SuiteRunner;
|
18
|
+
|
19
|
+
[Inject]
|
20
|
+
public var runnerResult:Result;
|
21
|
+
|
22
|
+
public function testRunTriggersCompleteEvent():void {
|
23
|
+
suiteRunner.addEventListener(Event.COMPLETE, async.add(checkResultWasNotSuccessful));
|
24
|
+
suiteRunner.run(DoubleFailSuite);
|
25
|
+
}
|
26
|
+
|
27
|
+
private function checkResultWasNotSuccessful(event:Event):void {
|
28
|
+
assertFalse(runnerResult.wasSuccessful);
|
29
|
+
}
|
30
|
+
|
31
|
+
[Test]
|
32
|
+
public function testCanHandATestToSuiteRunner():void {
|
33
|
+
suiteRunner.addEventListener(Event.COMPLETE, async.add());
|
34
|
+
suiteRunner.run(InjectionVerification);
|
35
|
+
assertFalse(runnerResult.wasSuccessful);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
|
@@ -0,0 +1,107 @@
|
|
1
|
+
package asunit.runners {
|
2
|
+
|
3
|
+
import asunit.asserts.*;
|
4
|
+
import asunit.framework.CallbackBridge;
|
5
|
+
import asunit.framework.TestCase;
|
6
|
+
import asunit.util.Iterator;
|
7
|
+
|
8
|
+
import asunit.framework.IAsync;
|
9
|
+
import asunit.framework.Method;
|
10
|
+
import asunit.framework.Result;
|
11
|
+
import asunit.framework.TestFailure;
|
12
|
+
import asunit.framework.TestIterator;
|
13
|
+
|
14
|
+
import flash.events.Event;
|
15
|
+
import flash.utils.getQualifiedClassName;
|
16
|
+
|
17
|
+
public class TestRunnerAsyncMethodTest {
|
18
|
+
|
19
|
+
[Inject]
|
20
|
+
public var async:IAsync;
|
21
|
+
|
22
|
+
[Inject]
|
23
|
+
public var runner:TestRunner;
|
24
|
+
|
25
|
+
[Test]
|
26
|
+
public function asyncShouldWork():void {
|
27
|
+
runner.addEventListener(Event.COMPLETE, async.add(ensureRunnerHasNotYetFailed, 100));
|
28
|
+
runner.run(AsyncMethodSuccessTest);
|
29
|
+
}
|
30
|
+
|
31
|
+
[Test]
|
32
|
+
public function runAsyncCallsAsyncDelegate():void {
|
33
|
+
runner.addEventListener(Event.COMPLETE, async.add(ensureRunnerHasNotYetFailed, 10));
|
34
|
+
runner.run(AsyncDelegateCalledSynchronouslyTest);
|
35
|
+
}
|
36
|
+
|
37
|
+
private function ensureRunnerHasNotYetFailed(e:Event):void {
|
38
|
+
assertFalse('runner result has not failed', runner.bridge.failureEncountered);
|
39
|
+
}
|
40
|
+
|
41
|
+
[Test]
|
42
|
+
public function shouldSeeErrorWhenAsyncFailure():void {
|
43
|
+
runner.addEventListener(Event.COMPLETE, async.add(checkResultForIllegalOperationError, 200));
|
44
|
+
runner.run(AsyncMethodTooSlowTest);
|
45
|
+
}
|
46
|
+
|
47
|
+
private function checkResultForIllegalOperationError(e:Event):void {
|
48
|
+
assertEquals('number of errors', 1, runner.bridge.errors.length);
|
49
|
+
var failure0:TestFailure = runner.bridge.errors[0] as TestFailure;
|
50
|
+
assertEquals('exception type', 'flash.errors::IllegalOperationError', getQualifiedClassName(failure0.thrownException));
|
51
|
+
assertEquals('failed method name', 'shouldFailForBeingTooSlow', failure0.failedMethod);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
import asunit.asserts.*;
|
57
|
+
import asunit.framework.IAsync;
|
58
|
+
import flash.utils.setTimeout;
|
59
|
+
|
60
|
+
class AsyncMethodSuccessTest {
|
61
|
+
|
62
|
+
[Inject]
|
63
|
+
public var async:IAsync;
|
64
|
+
|
65
|
+
[Test]
|
66
|
+
public function operationDelayedButFastEnoughToSucceed():void {
|
67
|
+
var delegate:Function = async.add();
|
68
|
+
setTimeout(delegate, 0);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
class AsyncMethodTooSlowTest {
|
73
|
+
|
74
|
+
[Inject]
|
75
|
+
public var async:IAsync;
|
76
|
+
|
77
|
+
[Test]
|
78
|
+
public function shouldFailForBeingTooSlow():void {
|
79
|
+
// This will force an async timeout in 1 millisecond:
|
80
|
+
var delegate:Function = async.add(null, 1);
|
81
|
+
// This will still call the async handler in 100ms,
|
82
|
+
// but the test run should have already continued:
|
83
|
+
setTimeout(delegate, 100);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
class AsyncDelegateCalledSynchronouslyTest {
|
88
|
+
|
89
|
+
import asunit.asserts.*;
|
90
|
+
|
91
|
+
[Inject]
|
92
|
+
public var async:IAsync;
|
93
|
+
|
94
|
+
private var handlerWasCalled:Boolean = false;
|
95
|
+
|
96
|
+
[Test]
|
97
|
+
public function callingDelegateSynchronouslyShouldStillSucceed():void {
|
98
|
+
var delegate:Function = async.add(onComplete);
|
99
|
+
delegate();
|
100
|
+
assertTrue(handlerWasCalled);
|
101
|
+
}
|
102
|
+
|
103
|
+
private function onComplete():void {
|
104
|
+
handlerWasCalled = true;
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|