asunit4 4.2.1.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,56 @@
|
|
1
|
+
package asunit.runners {
|
2
|
+
|
3
|
+
import asunit.framework.TestCase;
|
4
|
+
|
5
|
+
import asunit.framework.IResult;
|
6
|
+
import asunit.framework.Result;
|
7
|
+
import asunit.framework.TestFailure;
|
8
|
+
import asunit.support.ErrorInMethod;
|
9
|
+
|
10
|
+
import flash.events.Event;
|
11
|
+
|
12
|
+
public class TestRunnerErrorMethodTest extends TestCase {
|
13
|
+
|
14
|
+
private var runner:TestRunner;
|
15
|
+
private var testWithError:ErrorInMethod;
|
16
|
+
|
17
|
+
public function TestRunnerErrorMethodTest(testMethod:String = null) {
|
18
|
+
super(testMethod);
|
19
|
+
}
|
20
|
+
|
21
|
+
protected override function setUp():void {
|
22
|
+
super.setUp();
|
23
|
+
runner = new TestRunner();
|
24
|
+
testWithError = new ErrorInMethod();
|
25
|
+
}
|
26
|
+
|
27
|
+
protected override function tearDown():void {
|
28
|
+
super.tearDown();
|
29
|
+
runner = null;
|
30
|
+
testWithError = null;
|
31
|
+
}
|
32
|
+
|
33
|
+
public function testInstantiated():void {
|
34
|
+
assertTrue("TestRunner instantiated", runner is TestRunner);
|
35
|
+
}
|
36
|
+
|
37
|
+
public function test_run_with_errors():void {
|
38
|
+
runner.addEventListener(Event.COMPLETE, addAsync(check_Result_has_one_error, 100));
|
39
|
+
runner.run(ErrorInMethod);
|
40
|
+
}
|
41
|
+
|
42
|
+
private function check_Result_has_one_error(e:Event):void {
|
43
|
+
var runnerResult:IResult = runner.bridge;
|
44
|
+
assertFalse('runnerResult.wasSuccessful', runnerResult.wasSuccessful);
|
45
|
+
|
46
|
+
assertEquals('one error in testResult', 1, runnerResult.errorCount);
|
47
|
+
assertEquals('no failures in testResult', 0, runnerResult.failureCount);
|
48
|
+
|
49
|
+
var failure0:TestFailure = runnerResult.errors[0] as TestFailure;
|
50
|
+
assertTrue('thrownException is correct type', failure0.thrownException is ArgumentError);
|
51
|
+
assertTrue('failedTest is an instance of the test class', failure0.failedTest is ErrorInMethod);
|
52
|
+
assertSame('failedMethod name', 'throw_ArgumentError', failure0.failedMethod);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
@@ -0,0 +1,98 @@
|
|
1
|
+
package asunit.runners {
|
2
|
+
|
3
|
+
import asunit.errors.AssertionFailedError;
|
4
|
+
import asunit.framework.TestCase;
|
5
|
+
|
6
|
+
import asunit.framework.IResult;
|
7
|
+
import asunit.framework.Result;
|
8
|
+
import asunit.framework.TestFailure;
|
9
|
+
|
10
|
+
import flash.events.Event;
|
11
|
+
|
12
|
+
public class TestRunnerExpectsErrorTest extends TestCase {
|
13
|
+
|
14
|
+
private var runner:TestRunner;
|
15
|
+
private var successTest:Class;
|
16
|
+
private var throwNothingTest:Class;
|
17
|
+
private var throwWrongErrorTest:Class;
|
18
|
+
|
19
|
+
public function TestRunnerExpectsErrorTest(testMethod:String = null) {
|
20
|
+
super(testMethod);
|
21
|
+
}
|
22
|
+
|
23
|
+
protected override function setUp():void {
|
24
|
+
super.setUp();
|
25
|
+
runner = new TestRunner();
|
26
|
+
successTest = TestExpectsArgumentErrorAndThrowsIt;
|
27
|
+
throwNothingTest = TestExpectsArgumentErrorButThrowsNothing;
|
28
|
+
throwWrongErrorTest = TestExpectsArgumentErrorButThrowsWrongError;
|
29
|
+
}
|
30
|
+
|
31
|
+
protected override function tearDown():void {
|
32
|
+
super.tearDown();
|
33
|
+
runner = null;
|
34
|
+
successTest = null;
|
35
|
+
throwNothingTest = null;
|
36
|
+
throwWrongErrorTest = null;
|
37
|
+
}
|
38
|
+
|
39
|
+
public function test_method_expects_specific_error_and_throws_it_yields_successful_test_result():void {
|
40
|
+
runner.addEventListener(Event.COMPLETE, addAsync(check_Result_has_no_errors, 100));
|
41
|
+
runner.run(successTest);
|
42
|
+
}
|
43
|
+
|
44
|
+
private function check_Result_has_no_errors(e:Event):void {
|
45
|
+
var runnerResult:IResult = runner.bridge;
|
46
|
+
assertEquals('no errors in testResult', 0, runnerResult.errorCount);
|
47
|
+
assertEquals('no failures in testResult', 0, runnerResult.failureCount);
|
48
|
+
}
|
49
|
+
|
50
|
+
public function test_method_expects_specific_error_but_nothing_thrown_yields_assertion_failure():void {
|
51
|
+
runner.addEventListener(Event.COMPLETE, addAsync(check_Result_has_one_assertion_failure, 100));
|
52
|
+
runner.run(throwNothingTest);
|
53
|
+
}
|
54
|
+
|
55
|
+
private function check_Result_has_one_assertion_failure(e:Event):void {
|
56
|
+
var runnerResult:IResult = runner.bridge;
|
57
|
+
assertFalse(runnerResult.wasSuccessful);
|
58
|
+
|
59
|
+
assertEquals('one failure in testResult', 1, runnerResult.failureCount);
|
60
|
+
assertEquals('no errors in testResult', 0, runnerResult.errorCount);
|
61
|
+
|
62
|
+
var failure0:TestFailure = runnerResult.failures[0] as TestFailure;
|
63
|
+
assertTrue('thrownException is correct type', failure0.thrownException is AssertionFailedError);
|
64
|
+
assertTrue('failedTest is instance of the test class', failure0.failedTest is throwNothingTest);
|
65
|
+
assertSame('failedMethod name', 'fail_by_throwing_nothing', failure0.failedMethod);
|
66
|
+
}
|
67
|
+
|
68
|
+
public function test_method_expects_specific_error_but_wrong_one_thrown_yields_assertion_failure():void {
|
69
|
+
runner.addEventListener(Event.COMPLETE, addAsync(check_Result_has_one_assertion_failure, 100));
|
70
|
+
runner.run(throwNothingTest);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
class TestExpectsArgumentErrorAndThrowsIt {
|
76
|
+
|
77
|
+
[Test(expects="ArgumentError")]
|
78
|
+
public function throwArgumentError():void {
|
79
|
+
throw new ArgumentError('generated by TestExpectsArgumentError');
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
class TestExpectsArgumentErrorButThrowsNothing {
|
84
|
+
|
85
|
+
[Test(expects="ArgumentError")]
|
86
|
+
public function fail_by_throwing_nothing():void {
|
87
|
+
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
class TestExpectsArgumentErrorButThrowsWrongError {
|
92
|
+
|
93
|
+
[Test(expects="ArgumentError")]
|
94
|
+
public function fail_by_throwing_wrong_error():void {
|
95
|
+
throw new Error('generated by TestExpectsArgumentErrorButThrowsWrongError');
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
package asunit.runners {
|
2
|
+
|
3
|
+
import asunit.framework.TestCase;
|
4
|
+
|
5
|
+
import asunit.framework.Result;
|
6
|
+
import asunit.support.IgnoredMethod;
|
7
|
+
|
8
|
+
import flash.events.Event;
|
9
|
+
|
10
|
+
public class TestRunnerIgnoredMethodTest extends TestCase {
|
11
|
+
|
12
|
+
private var ignoredTest:Class;
|
13
|
+
private var runner:TestRunner;
|
14
|
+
|
15
|
+
public function TestRunnerIgnoredMethodTest(testMethod:String = null) {
|
16
|
+
super(testMethod);
|
17
|
+
}
|
18
|
+
|
19
|
+
protected override function setUp():void {
|
20
|
+
super.setUp();
|
21
|
+
ignoredTest = IgnoredMethod;
|
22
|
+
runner = new TestRunner();
|
23
|
+
}
|
24
|
+
|
25
|
+
protected override function tearDown():void {
|
26
|
+
super.tearDown();
|
27
|
+
ignoredTest = null;
|
28
|
+
runner = null;
|
29
|
+
}
|
30
|
+
|
31
|
+
public function testRunWithIgnoredMethod():void {
|
32
|
+
runner.addEventListener(Event.COMPLETE, addAsync(checkResultHasOneIgnoredMethod, 100));
|
33
|
+
runner.run(ignoredTest);
|
34
|
+
}
|
35
|
+
|
36
|
+
private function checkResultHasOneIgnoredMethod(e:Event):void {
|
37
|
+
assertFalse('runnerResult.failureEncountered', runner.bridge.failureEncountered);
|
38
|
+
assertEquals('one ignored test in result', 1, runner.bridge.ignoredTests.length);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
@@ -0,0 +1,171 @@
|
|
1
|
+
package asunit.runners {
|
2
|
+
|
3
|
+
import asunit.asserts.*;
|
4
|
+
import asunit.framework.Async;
|
5
|
+
import asunit.framework.IAsync;
|
6
|
+
import asunit.framework.IRunner;
|
7
|
+
import asunit.framework.ITestFailure;
|
8
|
+
import asunit.framework.Result;
|
9
|
+
import asunit.framework.TestCase;
|
10
|
+
import asunit.framework.TestFailure;
|
11
|
+
import asunit.support.AnnotatedSubClass;
|
12
|
+
import asunit.support.InjectTimeoutOnAsync;
|
13
|
+
import asunit.support.InjectionFailure;
|
14
|
+
import asunit.support.InjectionVerification;
|
15
|
+
import asunit.support.MultiMethod;
|
16
|
+
|
17
|
+
import flash.events.Event;
|
18
|
+
import flash.display.Sprite;
|
19
|
+
|
20
|
+
public class TestRunnerTest {
|
21
|
+
|
22
|
+
[Inject]
|
23
|
+
public var async:IAsync;
|
24
|
+
|
25
|
+
[Inject]
|
26
|
+
public var context:Sprite;
|
27
|
+
|
28
|
+
private var runner:TestRunner;
|
29
|
+
private var test:Class;
|
30
|
+
|
31
|
+
[Before]
|
32
|
+
public function setUp():void {
|
33
|
+
runner = new TestRunner();
|
34
|
+
|
35
|
+
// Yes, statics are ugly, but we're testing
|
36
|
+
// that static methods are called, e.g. [BeforeClass].
|
37
|
+
MultiMethod.methodsCalled = [];
|
38
|
+
test = MultiMethod;
|
39
|
+
}
|
40
|
+
|
41
|
+
[After]
|
42
|
+
public function tearDown():void {
|
43
|
+
runner = null;
|
44
|
+
MultiMethod.methodsCalled = null;
|
45
|
+
}
|
46
|
+
|
47
|
+
[Test]
|
48
|
+
public function runnerInstantiated():void {
|
49
|
+
assertTrue("TestRunner instantiated", runner is IRunner);
|
50
|
+
}
|
51
|
+
|
52
|
+
[Test]
|
53
|
+
public function testShouldNotExtendTestCase():void {
|
54
|
+
assertFalse(test is TestCase);
|
55
|
+
}
|
56
|
+
|
57
|
+
[Test]
|
58
|
+
public function shouldRunMethodsAlphabetically():void {
|
59
|
+
runner.addEventListener(Event.COMPLETE, async.add(checkMethodsCalledAfterRunningTestInstance, 500));
|
60
|
+
runner.run(test);
|
61
|
+
}
|
62
|
+
|
63
|
+
private function checkMethodsCalledAfterRunningTestInstance(e:Event):void {
|
64
|
+
var i:uint = 0;
|
65
|
+
|
66
|
+
assertSame(MultiMethod.runBeforeClass1, MultiMethod.methodsCalled[i++]);
|
67
|
+
assertSame(MultiMethod.runBeforeClass2, MultiMethod.methodsCalled[i++]);
|
68
|
+
|
69
|
+
assertSame(runner.currentTest.runBefore1, MultiMethod.methodsCalled[i++]);
|
70
|
+
assertSame(runner.currentTest.runBefore2, MultiMethod.methodsCalled[i++]);
|
71
|
+
assertSame(runner.currentTest.fail_assertEquals, MultiMethod.methodsCalled[i++]);
|
72
|
+
assertSame(runner.currentTest.runAfter1, MultiMethod.methodsCalled[i++]);
|
73
|
+
assertSame(runner.currentTest.runAfter2, MultiMethod.methodsCalled[i++]);
|
74
|
+
|
75
|
+
assertSame(runner.currentTest.runBefore1, MultiMethod.methodsCalled[i++]);
|
76
|
+
assertSame(runner.currentTest.runBefore2, MultiMethod.methodsCalled[i++]);
|
77
|
+
assertSame(runner.currentTest.numChildren_is_0_by_default, MultiMethod.methodsCalled[i++]);
|
78
|
+
assertSame(runner.currentTest.runAfter1, MultiMethod.methodsCalled[i++]);
|
79
|
+
assertSame(runner.currentTest.runAfter2, MultiMethod.methodsCalled[i++]);
|
80
|
+
|
81
|
+
assertSame(runner.currentTest.runBefore1, MultiMethod.methodsCalled[i++]);
|
82
|
+
assertSame(runner.currentTest.runBefore2, MultiMethod.methodsCalled[i++]);
|
83
|
+
assertSame(runner.currentTest.stage_is_null_by_default, MultiMethod.methodsCalled[i++]);
|
84
|
+
assertSame(runner.currentTest.runAfter1, MultiMethod.methodsCalled[i++]);
|
85
|
+
assertSame(runner.currentTest.runAfter2, MultiMethod.methodsCalled[i++]);
|
86
|
+
|
87
|
+
assertSame(MultiMethod.runAfterClass1, MultiMethod.methodsCalled[i++]);
|
88
|
+
assertSame(MultiMethod.runAfterClass2, MultiMethod.methodsCalled[i++]);
|
89
|
+
|
90
|
+
assertEquals('checked all methodsCalled', MultiMethod.methodsCalled.length, i);
|
91
|
+
}
|
92
|
+
|
93
|
+
[Test]
|
94
|
+
public function runShouldTriggerResultEvent():void {
|
95
|
+
runner.addEventListener(Event.COMPLETE, async.add(checkResultWasNotSuccessful, 500));
|
96
|
+
runner.run(test);
|
97
|
+
}
|
98
|
+
|
99
|
+
private function checkResultWasNotSuccessful(e:Event):void {
|
100
|
+
assertTrue(runner.bridge.failureEncountered);
|
101
|
+
assertFalse(runner.bridge.wasSuccessful);
|
102
|
+
|
103
|
+
var failures:Array = runner.bridge.failures;
|
104
|
+
assertEquals('one failure in testResult', 1, failures.length);
|
105
|
+
|
106
|
+
var failure0:ITestFailure = failures[0] as TestFailure;
|
107
|
+
assertTrue("failedTest is instance of test class", failure0.failedTest is test);
|
108
|
+
}
|
109
|
+
|
110
|
+
[Test]
|
111
|
+
public function runMethodByNameShouldExecuteExpectedSequence():void {
|
112
|
+
var delegate:Function = async.add(checkMethodsCalledAfterRunningTestMethodByName, 500);
|
113
|
+
runner.addEventListener(Event.COMPLETE, delegate);
|
114
|
+
|
115
|
+
var testMethodName:String = 'stage_is_null_by_default';
|
116
|
+
runner.runMethodByName(test, testMethodName);
|
117
|
+
}
|
118
|
+
|
119
|
+
private function checkMethodsCalledAfterRunningTestMethodByName(e:Event):void {
|
120
|
+
var i:uint = 0;
|
121
|
+
|
122
|
+
assertSame(MultiMethod.runBeforeClass1, MultiMethod.methodsCalled[i++]);
|
123
|
+
assertSame(MultiMethod.runBeforeClass2, MultiMethod.methodsCalled[i++]);
|
124
|
+
|
125
|
+
assertSame(runner.currentTest.runBefore1, MultiMethod.methodsCalled[i++]);
|
126
|
+
assertSame(runner.currentTest.runBefore2, MultiMethod.methodsCalled[i++]);
|
127
|
+
assertSame(runner.currentTest.stage_is_null_by_default, MultiMethod.methodsCalled[i++]);
|
128
|
+
|
129
|
+
// NOTE: The following assertions are no longer applicable.
|
130
|
+
// if the testMethod is provided, tearDown does not occur...
|
131
|
+
//assertSame(runner.currentTest.runAfter1, MultiMethod.methodsCalled[i++]);
|
132
|
+
//assertSame(runner.currentTest.runAfter2, MultiMethod.methodsCalled[i++]);
|
133
|
+
|
134
|
+
//assertSame(MultiMethod.runAfterClass1, MultiMethod.methodsCalled[i++]);
|
135
|
+
//assertSame(MultiMethod.runAfterClass2, MultiMethod.methodsCalled[i++]);
|
136
|
+
|
137
|
+
assertEquals('checked all methodsCalled', MultiMethod.methodsCalled.length, i);
|
138
|
+
}
|
139
|
+
|
140
|
+
// This an interesting hack in that an AsUnit 4 Test Case is being instantiated
|
141
|
+
// and executed, but in this environment, we're simply checking to see if it passed,
|
142
|
+
// and outputing any failures to the message...
|
143
|
+
[Test]
|
144
|
+
public function shouldInjectTypes():void {
|
145
|
+
runner.run(InjectionVerification, null, context);
|
146
|
+
assertFalse("Should not have encountered failures: " + runner.bridge.failures.join("\n\n"), runner.bridge.failureEncountered);
|
147
|
+
}
|
148
|
+
|
149
|
+
[Test]
|
150
|
+
public function shouldInjectWithUnknownAttribute():void {
|
151
|
+
runner.run(InjectionFailure);
|
152
|
+
var warnings:Array = runner.bridge.warnings;
|
153
|
+
assertEquals(1, warnings.length);
|
154
|
+
}
|
155
|
+
|
156
|
+
[Test]
|
157
|
+
public function shouldInjectAsyncTimeout():void {
|
158
|
+
var async:IAsync = runner.async;
|
159
|
+
assertEquals(Async.DEFAULT_TIMEOUT, async.timeout);
|
160
|
+
runner.run(InjectTimeoutOnAsync);
|
161
|
+
assertEquals(5, async.timeout);
|
162
|
+
}
|
163
|
+
|
164
|
+
[Test]
|
165
|
+
public function annotationsOnSuperClassShouldBeRespected():void {
|
166
|
+
runner.run(AnnotatedSubClass);
|
167
|
+
assertFalse("Should not have failures: " + runner.bridge.failures.join("\n\n"), runner.bridge.failureEncountered);
|
168
|
+
}
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
package asunit.support {
|
2
|
+
|
3
|
+
import asunit.asserts.*;
|
4
|
+
|
5
|
+
public class AnnotatedSubClass extends AnnotatedSuperClass {
|
6
|
+
|
7
|
+
[Test]
|
8
|
+
public function verifyDictionary():void {
|
9
|
+
assertNotNull(dictionary);
|
10
|
+
}
|
11
|
+
|
12
|
+
[Test]
|
13
|
+
public function verifyAsync():void {
|
14
|
+
assertNotNull(async);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
package asunit.support {
|
2
|
+
|
3
|
+
import asunit.asserts.*;
|
4
|
+
import asunit.framework.IAsync;
|
5
|
+
import flash.utils.Dictionary;
|
6
|
+
|
7
|
+
public class AnnotatedSuperClass {
|
8
|
+
|
9
|
+
[Inject]
|
10
|
+
public var async:IAsync;
|
11
|
+
|
12
|
+
[Inject]
|
13
|
+
public var dictionary:Dictionary;
|
14
|
+
}
|
15
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
package asunit.support {
|
2
|
+
|
3
|
+
public class CustomParameters {
|
4
|
+
|
5
|
+
public var someArray:Array;
|
6
|
+
public var someBoolean:Boolean;
|
7
|
+
public var someInt:int;
|
8
|
+
public var someNumber:Number;
|
9
|
+
public var someString:String;
|
10
|
+
public var someUInt:uint;
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
package asunit.support {
|
2
|
+
|
3
|
+
import asunit.framework.CallbackBridge;
|
4
|
+
import asunit.framework.IResult;
|
5
|
+
import asunit.runners.TestRunner;
|
6
|
+
|
7
|
+
import flash.display.DisplayObjectContainer;
|
8
|
+
|
9
|
+
public class CustomTestRunner extends TestRunner {
|
10
|
+
|
11
|
+
// Used so that test cases can
|
12
|
+
// verify that this custom runner
|
13
|
+
// worked.
|
14
|
+
public static var runCalledCount:int;
|
15
|
+
|
16
|
+
override public function run(testClass:Class, testMethod:String=null, visualContext:DisplayObjectContainer=null):void {
|
17
|
+
runCalledCount++;
|
18
|
+
super.run(testClass, testMethod, visualContext);
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
package asunit.support {
|
2
|
+
|
3
|
+
[Suite]
|
4
|
+
public class DoubleNestedSuite {
|
5
|
+
// contains two suites
|
6
|
+
public var suiteOfTwoSuites:SuiteOfTwoSuites;
|
7
|
+
|
8
|
+
// contains a single test
|
9
|
+
public var singleErrorSuite:SingleErrorSuite;
|
10
|
+
|
11
|
+
// a single test not in a suite
|
12
|
+
public var ignoredMethodTest:IgnoredMethod;
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
package asunit.support {
|
2
|
+
|
3
|
+
import asunit.asserts.*;
|
4
|
+
|
5
|
+
public class FailAssertEquals {
|
6
|
+
|
7
|
+
public var methodsCalled:Array;
|
8
|
+
|
9
|
+
public function FailAssertEquals() {
|
10
|
+
methodsCalled = [];
|
11
|
+
}
|
12
|
+
|
13
|
+
[Before]
|
14
|
+
public function runBefore():void {
|
15
|
+
methodsCalled.push(arguments.callee);
|
16
|
+
}
|
17
|
+
|
18
|
+
[After]
|
19
|
+
public function runAfter():void {
|
20
|
+
methodsCalled.push(arguments.callee);
|
21
|
+
}
|
22
|
+
|
23
|
+
[Test]
|
24
|
+
public function fail_assertEquals():void {
|
25
|
+
methodsCalled.push(arguments.callee);
|
26
|
+
assertEquals('Words should be equal', 'right', 'wrong');
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
package asunit.support {
|
2
|
+
|
3
|
+
import asunit.asserts.*;
|
4
|
+
|
5
|
+
public class FailAssertTrue {
|
6
|
+
|
7
|
+
public var methodsCalled:Array;
|
8
|
+
|
9
|
+
[Before]
|
10
|
+
public function runBefore():void {
|
11
|
+
methodsCalled = [];
|
12
|
+
methodsCalled.push(arguments.callee);
|
13
|
+
}
|
14
|
+
|
15
|
+
[After]
|
16
|
+
public function runAfter():void {
|
17
|
+
methodsCalled.push(arguments.callee);
|
18
|
+
}
|
19
|
+
|
20
|
+
[Test]
|
21
|
+
public function fail_assertTrue():void {
|
22
|
+
methodsCalled.push(arguments.callee);
|
23
|
+
assertTrue('Law of non-contradiction', false);
|
24
|
+
}
|
25
|
+
|
26
|
+
}
|
27
|
+
|
28
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
package asunit.support {
|
2
|
+
|
3
|
+
import asunit.framework.IResult;
|
4
|
+
import asunit.framework.IRunListener;
|
5
|
+
import asunit.framework.ITestFailure;
|
6
|
+
import asunit.framework.ITestSuccess;
|
7
|
+
import asunit.framework.ITestWarning;
|
8
|
+
import asunit.framework.Method;
|
9
|
+
|
10
|
+
public class FakeObserver implements IRunListener {
|
11
|
+
|
12
|
+
public var onRunStartedCalled:Boolean;
|
13
|
+
public var onTestStartedCalled:Boolean;
|
14
|
+
|
15
|
+
public function onRunStarted():void {
|
16
|
+
onRunStartedCalled = true;
|
17
|
+
}
|
18
|
+
|
19
|
+
public function onRunCompleted(result:IResult):void {
|
20
|
+
}
|
21
|
+
|
22
|
+
public function onTestStarted(test:Object):void {
|
23
|
+
onTestStartedCalled = true;
|
24
|
+
}
|
25
|
+
|
26
|
+
public function onTestCompleted(test:Object):void {
|
27
|
+
}
|
28
|
+
|
29
|
+
public function onTestFailure(failure:ITestFailure):void {
|
30
|
+
}
|
31
|
+
|
32
|
+
public function onTestSuccess(success:ITestSuccess):void {
|
33
|
+
}
|
34
|
+
|
35
|
+
public function onTestIgnored(method:Method):void {
|
36
|
+
}
|
37
|
+
|
38
|
+
public function onWarning(warning:ITestWarning):void {
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
package asunit.support {
|
2
|
+
|
3
|
+
import asunit.framework.IRunner;
|
4
|
+
import asunit.framework.IResult;
|
5
|
+
import asunit.framework.TestSuccess;
|
6
|
+
import asunit.framework.IRunnerFactory;
|
7
|
+
|
8
|
+
import flash.events.EventDispatcher;
|
9
|
+
import flash.display.DisplayObjectContainer;
|
10
|
+
|
11
|
+
public class FakeRunner extends EventDispatcher implements IRunner {
|
12
|
+
|
13
|
+
public function run(testOrSuite:Class, result:IResult, testMethod:String=null, visualContext:DisplayObjectContainer=null):void {
|
14
|
+
var currentTest:TestForFakeRunner = new testOrSuite() as TestForFakeRunner;
|
15
|
+
|
16
|
+
result.onTestStarted(currentTest);
|
17
|
+
result.onTestSuccess(new TestSuccess(currentTest, 'customTestMethod'));
|
18
|
+
result.onTestCompleted(currentTest);
|
19
|
+
}
|
20
|
+
|
21
|
+
public function shouldRunTest(testClass:Class):Boolean {
|
22
|
+
return true;
|
23
|
+
}
|
24
|
+
|
25
|
+
public function set factory(factory:IRunnerFactory):void {
|
26
|
+
}
|
27
|
+
|
28
|
+
public function get factory():IRunnerFactory {
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
package asunit.support {
|
2
|
+
|
3
|
+
import asunit.asserts.*;
|
4
|
+
|
5
|
+
public class IgnoredMethod {
|
6
|
+
|
7
|
+
[Before]
|
8
|
+
public function runBefore():void {
|
9
|
+
}
|
10
|
+
|
11
|
+
[After]
|
12
|
+
public function runAfter():void {
|
13
|
+
}
|
14
|
+
|
15
|
+
[Ignore("because")]
|
16
|
+
[Test]
|
17
|
+
public function should_be_ignored():void {
|
18
|
+
fail('this test method should be ignored');
|
19
|
+
}
|
20
|
+
|
21
|
+
[Test]
|
22
|
+
public function should_not_be_ignored():void {
|
23
|
+
}
|
24
|
+
|
25
|
+
}
|
26
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
package asunit.support {
|
2
|
+
|
3
|
+
import asunit.asserts.*;
|
4
|
+
import asunit.framework.Async;
|
5
|
+
import asunit.framework.IAsync;
|
6
|
+
|
7
|
+
import flash.display.Sprite;
|
8
|
+
|
9
|
+
public class InjectionFailure {
|
10
|
+
|
11
|
+
[Inject(unknownValue="foo")]
|
12
|
+
public var custom:CustomParameters;
|
13
|
+
|
14
|
+
[Test]
|
15
|
+
public function unknownValueShouldExplode():void {
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|