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,79 @@
|
|
1
|
+
package asunit.framework {
|
2
|
+
|
3
|
+
import asunit.asserts.*;
|
4
|
+
|
5
|
+
public class InjectionDelegateTest {
|
6
|
+
|
7
|
+
[Inject]
|
8
|
+
public var injector:InjectionDelegate;
|
9
|
+
|
10
|
+
[Test]
|
11
|
+
public function testInstantiated():void {
|
12
|
+
assertTrue("instance is InjectionDelegate", injector is InjectionDelegate);
|
13
|
+
}
|
14
|
+
|
15
|
+
[Test]
|
16
|
+
public function testUpdateInjectionPoints():void {
|
17
|
+
var addict:Addict = new Addict();
|
18
|
+
injector.updateInjectionPoints(addict);
|
19
|
+
assertNotNull(addict.array);
|
20
|
+
}
|
21
|
+
|
22
|
+
[Test]
|
23
|
+
public function injectedInstancesShouldBeCached():void {
|
24
|
+
var addict:Addict = new Addict();
|
25
|
+
var addict2:Addict = new Addict();
|
26
|
+
|
27
|
+
injector.updateInjectionPoints(addict);
|
28
|
+
injector.updateInjectionPoints(addict2);
|
29
|
+
|
30
|
+
assertSame(addict.array, addict2.array);
|
31
|
+
|
32
|
+
}
|
33
|
+
|
34
|
+
[Test(expects="asunit.errors.UsageError")]
|
35
|
+
public function shouldThrowUsageErrorOnInvalidAddict():void
|
36
|
+
{
|
37
|
+
var invalidAddict:AddictWithNoInjections = new AddictWithNoInjections();
|
38
|
+
injector.updateInjectionPoints(invalidAddict, InjectionDelegate.THROW_ERROR_ON_MISSING_INJECTION_POINT);
|
39
|
+
}
|
40
|
+
|
41
|
+
[Test(expects="asunit.errors.UsageError")]
|
42
|
+
public function shouldThrowUsageErrorIfNoVariableInjectionsFound():void
|
43
|
+
{
|
44
|
+
var invalidAddict:AddictWithOnlyMethodInjection = new AddictWithOnlyMethodInjection();
|
45
|
+
injector.updateInjectionPoints(invalidAddict, InjectionDelegate.THROW_ERROR_ON_MISSING_INJECTION_POINT);
|
46
|
+
}
|
47
|
+
|
48
|
+
[Test]
|
49
|
+
public function shouldNotThrowUsageErrorOnInvalidAddict():void
|
50
|
+
{
|
51
|
+
var invalidAddict:AddictWithNoInjections = new AddictWithNoInjections();
|
52
|
+
injector.updateInjectionPoints(invalidAddict);
|
53
|
+
}
|
54
|
+
|
55
|
+
[Test]
|
56
|
+
public function shouldNotThrowUsageErrorIfNoVariableInjectionsFound():void
|
57
|
+
{
|
58
|
+
var invalidAddict:AddictWithOnlyMethodInjection = new AddictWithOnlyMethodInjection();
|
59
|
+
injector.updateInjectionPoints(invalidAddict);
|
60
|
+
}
|
61
|
+
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
//An addict that has no inject annotations
|
66
|
+
class AddictWithNoInjections {}
|
67
|
+
|
68
|
+
class AddictWithOnlyMethodInjection {
|
69
|
+
[Inject]
|
70
|
+
public function pleaseInjectMe(array:Array):void{};
|
71
|
+
}
|
72
|
+
|
73
|
+
class Addict {
|
74
|
+
[Inject]
|
75
|
+
public var array:Array;
|
76
|
+
|
77
|
+
[Inject]
|
78
|
+
public function pleaseInjectMe(array:Array):void{};
|
79
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<books>
|
2
|
+
<book publisher="Addison-Wesley" name="Design Patterns" />
|
3
|
+
<book publisher="Addison-Wesley" name="The Pragmatic Programmer" />
|
4
|
+
<book publisher="Addison-Wesley" name="Test Driven Development" />
|
5
|
+
<book publisher="Addison-Wesley" name="Refactoring to Patterns" />
|
6
|
+
<book publisher="O'Reilly Media" name="The Cathedral & the Bazaar" />
|
7
|
+
<book publisher="O'Reilly Media" name="Unit Test Frameworks" />
|
8
|
+
</books>
|
@@ -0,0 +1,59 @@
|
|
1
|
+
package asunit.framework {
|
2
|
+
|
3
|
+
import asunit.framework.TestCase;
|
4
|
+
|
5
|
+
import asunit.support.FailAssertEquals;
|
6
|
+
import asunit.support.FailAssertTrue;
|
7
|
+
import asunit.support.SucceedAssertTrue;
|
8
|
+
import asunit.support.SuiteOfTwoSuites;
|
9
|
+
|
10
|
+
public class NestedSuiteIteratorTest extends TestCase {
|
11
|
+
private var iterator:SuiteIterator;
|
12
|
+
private var suiteClass:Class;
|
13
|
+
|
14
|
+
public function NestedSuiteIteratorTest(testMethod:String = null) {
|
15
|
+
super(testMethod);
|
16
|
+
}
|
17
|
+
|
18
|
+
protected override function setUp():void {
|
19
|
+
suiteClass = SuiteOfTwoSuites;
|
20
|
+
}
|
21
|
+
|
22
|
+
protected override function tearDown():void {
|
23
|
+
iterator = null;
|
24
|
+
}
|
25
|
+
|
26
|
+
public function test_length_from_SuiteIterator():void {
|
27
|
+
var iterator:SuiteIterator = new SuiteIterator(suiteClass);
|
28
|
+
assertEquals(3, iterator.length);
|
29
|
+
}
|
30
|
+
|
31
|
+
public function test_isSuite_false_with_test_class():void {
|
32
|
+
var iterator:SuiteIterator = new SuiteIterator(SucceedAssertTrue);
|
33
|
+
assertEquals(1, iterator.length);
|
34
|
+
}
|
35
|
+
|
36
|
+
public function test_getTestClasses_of_suite_class():void {
|
37
|
+
var iterator:SuiteIterator = new SuiteIterator(suiteClass);
|
38
|
+
assertEquals(3, iterator.length);
|
39
|
+
assertSame(FailAssertEquals, iterator.next());
|
40
|
+
assertSame(FailAssertTrue, iterator.next());
|
41
|
+
assertSame(SucceedAssertTrue, iterator.next());
|
42
|
+
}
|
43
|
+
|
44
|
+
public function test_iterator_for_suite_class_with_2_nested_suites_hasNext():void {
|
45
|
+
iterator = new SuiteIterator(suiteClass);
|
46
|
+
assertTrue(iterator.hasNext());
|
47
|
+
}
|
48
|
+
|
49
|
+
public function test_iterator_next():void {
|
50
|
+
iterator = new SuiteIterator(suiteClass);
|
51
|
+
|
52
|
+
assertSame(FailAssertEquals, iterator.next());
|
53
|
+
assertSame(FailAssertTrue, iterator.next());
|
54
|
+
assertSame(SucceedAssertTrue, iterator.next());
|
55
|
+
|
56
|
+
assertFalse('no methods left in iterator', iterator.hasNext());
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
@@ -0,0 +1,109 @@
|
|
1
|
+
package asunit.framework {
|
2
|
+
|
3
|
+
import asunit.asserts.*;
|
4
|
+
import asunit.events.TimeoutCommandEvent;
|
5
|
+
import asunit.framework.ErrorEvent;
|
6
|
+
import asunit.framework.TestCase;
|
7
|
+
|
8
|
+
import flash.events.Event;
|
9
|
+
import flash.events.EventDispatcher;
|
10
|
+
import flash.events.IEventDispatcher;
|
11
|
+
import flash.utils.clearTimeout;
|
12
|
+
import flash.utils.setTimeout;
|
13
|
+
|
14
|
+
public class ProceedOnEventTest {
|
15
|
+
|
16
|
+
[Inject]
|
17
|
+
public var async:IAsync;
|
18
|
+
|
19
|
+
[Inject]
|
20
|
+
public var dispatcher:EventDispatcher;
|
21
|
+
|
22
|
+
private var orphanAsync:IAsync;
|
23
|
+
private var command:TimeoutCommand;
|
24
|
+
private var timeoutID:int = -1;
|
25
|
+
|
26
|
+
[Before]
|
27
|
+
public function setUp():void {
|
28
|
+
orphanAsync = new Async();
|
29
|
+
}
|
30
|
+
|
31
|
+
[After]
|
32
|
+
public function tearDown():void {
|
33
|
+
command = null;
|
34
|
+
orphanAsync = null;
|
35
|
+
timeoutID = -1;
|
36
|
+
}
|
37
|
+
|
38
|
+
protected function foo():void { }
|
39
|
+
|
40
|
+
[Test]
|
41
|
+
public function proceedOnEventShouldDispatchCorrectEventAndClearPendingCommands():void {
|
42
|
+
orphanAsync.proceedOnEvent(dispatcher, Event.COMPLETE, 10);
|
43
|
+
|
44
|
+
var commands:Array = orphanAsync.getPending();
|
45
|
+
assertEquals("one pending command for test after proceedOnEvent()", 1, commands.length);
|
46
|
+
|
47
|
+
// send the correct event synchronously
|
48
|
+
dispatchCompleteEvent();
|
49
|
+
|
50
|
+
var message:String = "No pending commands for test after correct Event dispatched.";
|
51
|
+
assertEquals(message, 0, orphanAsync.getPending().length);
|
52
|
+
}
|
53
|
+
|
54
|
+
protected function dispatchCompleteEvent():void {
|
55
|
+
dispatcher.dispatchEvent(new Event(Event.COMPLETE));
|
56
|
+
}
|
57
|
+
|
58
|
+
[Test]
|
59
|
+
public function proceedOnEventShouldTimeoutAppropriately():void {
|
60
|
+
|
61
|
+
// Grab a reference to the Dispatcher so that we still have
|
62
|
+
// it after the test run (Fixing uncaught RTE null pointer exception)
|
63
|
+
var source:IEventDispatcher = dispatcher;
|
64
|
+
|
65
|
+
// This is the initial setup, we want test execution to pause
|
66
|
+
// for 1ms OR until the COMPLETE event fires:
|
67
|
+
orphanAsync.proceedOnEvent(source, Event.COMPLETE, 1);
|
68
|
+
|
69
|
+
// Get the Command so that we can just wait for the TIMED_OUT event:
|
70
|
+
var commands:Array = orphanAsync.getPending();
|
71
|
+
var command:TimeoutCommand = commands[0];
|
72
|
+
command.addEventListener(TimeoutCommandEvent.TIMED_OUT, async.add(onAsyncMethodFailed, 500));
|
73
|
+
|
74
|
+
// send the correct event too slowly
|
75
|
+
timeoutID = setTimeout(function():void {
|
76
|
+
source.dispatchEvent(new Event(Event.COMPLETE));
|
77
|
+
}, 10);
|
78
|
+
}
|
79
|
+
|
80
|
+
protected function onAsyncMethodFailed(event:TimeoutCommandEvent):void {
|
81
|
+
assertEquals("event type", TimeoutCommandEvent.TIMED_OUT, event.type);
|
82
|
+
clearTimeout(timeoutID);
|
83
|
+
}
|
84
|
+
|
85
|
+
[Test]
|
86
|
+
public function proceedOnEventShouldSendCALLEDEventAsExpected():void {
|
87
|
+
orphanAsync.proceedOnEvent(dispatcher, Event.COMPLETE, 10);
|
88
|
+
|
89
|
+
command = orphanAsync.getPending()[0];
|
90
|
+
|
91
|
+
// Use AsUnit 3's orphanAsync.add() to verify onAsyncMethodCalled is called.
|
92
|
+
command.addEventListener(TimeoutCommandEvent.CALLED, async.add(onAsyncMethodCalled));
|
93
|
+
|
94
|
+
// If all goes well, the ErrorEvent won't be dispatched.
|
95
|
+
command.addEventListener(ErrorEvent.ERROR, failIfCalled);
|
96
|
+
|
97
|
+
// send the correct event faster than orphanAsync.proceedOnEvent duration
|
98
|
+
setTimeout(dispatchCompleteEvent, 0);
|
99
|
+
}
|
100
|
+
|
101
|
+
protected function onAsyncMethodCalled(e:Event):void {
|
102
|
+
assertEquals("event type", TimeoutCommandEvent.CALLED, e.type);
|
103
|
+
}
|
104
|
+
|
105
|
+
protected function failIfCalled(e:Event = null):void {
|
106
|
+
fail("ProceedOnEventTest: This function should not have been called");
|
107
|
+
}
|
108
|
+
}
|
109
|
+
}
|
@@ -0,0 +1,92 @@
|
|
1
|
+
package asunit.framework {
|
2
|
+
|
3
|
+
import asunit.framework.TestCase;
|
4
|
+
import asunit.framework.ITestSuccess;
|
5
|
+
import asunit.framework.TestSuccess;
|
6
|
+
import asunit.framework.ITestFailure;
|
7
|
+
import asunit.framework.TestFailure;
|
8
|
+
import asunit.framework.IResult;
|
9
|
+
import asunit.framework.Result;
|
10
|
+
|
11
|
+
public class ResultTest extends TestCase {
|
12
|
+
|
13
|
+
private var test:*;
|
14
|
+
private var success:ITestSuccess;
|
15
|
+
private var failure:ITestFailure;
|
16
|
+
private var testResult:IResult;
|
17
|
+
|
18
|
+
public function ResultTest(methodName:String=null) {
|
19
|
+
super(methodName)
|
20
|
+
}
|
21
|
+
|
22
|
+
override protected function setUp():void {
|
23
|
+
super.setUp();
|
24
|
+
failure = new TestFailure(test, 'testSomethingThatFails', new Error('Fake Failure'));
|
25
|
+
success = new TestSuccess(test, 'testSomethingThatSucceeds');
|
26
|
+
test = new TestCase();
|
27
|
+
testResult = new Result();
|
28
|
+
}
|
29
|
+
|
30
|
+
override protected function tearDown():void {
|
31
|
+
super.tearDown();
|
32
|
+
failure = null;
|
33
|
+
success = null;
|
34
|
+
test = null;
|
35
|
+
testResult = null;
|
36
|
+
}
|
37
|
+
|
38
|
+
private function runSingleSuccess():void {
|
39
|
+
testResult.onRunStarted();
|
40
|
+
testResult.onTestStarted(test);
|
41
|
+
testResult.onTestSuccess(success);
|
42
|
+
testResult.onTestCompleted(test);
|
43
|
+
testResult.onRunCompleted(null);
|
44
|
+
}
|
45
|
+
|
46
|
+
private function runSingleFailure():void {
|
47
|
+
testResult.onRunStarted();
|
48
|
+
testResult.onTestStarted(test);
|
49
|
+
testResult.onTestFailure(failure);
|
50
|
+
testResult.onTestCompleted(test);
|
51
|
+
testResult.onRunCompleted(testResult);
|
52
|
+
}
|
53
|
+
|
54
|
+
private function runSingleIgnore():void {
|
55
|
+
testResult.onRunStarted();
|
56
|
+
testResult.onTestStarted(test);
|
57
|
+
testResult.onTestIgnored(null);
|
58
|
+
testResult.onTestCompleted(test);
|
59
|
+
testResult.onRunCompleted(testResult);
|
60
|
+
}
|
61
|
+
|
62
|
+
public function testRunWithSingleSuccess():void {
|
63
|
+
assertFalse("before test run", testResult.wasSuccessful);
|
64
|
+
runSingleSuccess();
|
65
|
+
assertFalse("failure encountered", testResult.failureEncountered);
|
66
|
+
assertTrue("after test complete", testResult.wasSuccessful);
|
67
|
+
assertEquals(1, testResult.runCount);
|
68
|
+
}
|
69
|
+
|
70
|
+
public function testRunWithSingleFailure():void {
|
71
|
+
runSingleFailure();
|
72
|
+
assertTrue("failure encountered", testResult.failureEncountered);
|
73
|
+
assertFalse("after test complete", testResult.wasSuccessful);
|
74
|
+
assertEquals(1, testResult.runCount);
|
75
|
+
}
|
76
|
+
|
77
|
+
public function testRunWithSingleError():void {
|
78
|
+
runSingleFailure();
|
79
|
+
assertTrue("failure encountered", testResult.failureEncountered);
|
80
|
+
assertFalse("after test complete", testResult.wasSuccessful);
|
81
|
+
assertEquals(1, testResult.runCount);
|
82
|
+
}
|
83
|
+
|
84
|
+
public function testRunCountWithSingleIgnore():void {
|
85
|
+
runSingleIgnore();
|
86
|
+
assertFalse("failure encountered", testResult.failureEncountered);
|
87
|
+
assertTrue("after test complete", testResult.wasSuccessful);
|
88
|
+
assertEquals(0, testResult.runCount);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
package asunit.framework {
|
2
|
+
|
3
|
+
import asunit.asserts.*;
|
4
|
+
import asunit.errors.UsageError;
|
5
|
+
import asunit.framework.IRunner;
|
6
|
+
import asunit.runners.TestRunner;
|
7
|
+
import asunit.runners.SuiteRunner;
|
8
|
+
import asunit.support.RunWithButNoType;
|
9
|
+
import asunit.support.RunWithSuiteButNoType;
|
10
|
+
import asunit.support.SingleSuccessSuite;
|
11
|
+
import asunit.support.SucceedAssertTrue;
|
12
|
+
|
13
|
+
import flash.display.Sprite;
|
14
|
+
|
15
|
+
public class RunnerFactoryTest {
|
16
|
+
|
17
|
+
[Inject]
|
18
|
+
public var factory:RunnerFactory;
|
19
|
+
|
20
|
+
[Test]
|
21
|
+
public function shouldCreateDefaultRunner():void {
|
22
|
+
var result:IRunner = factory.runnerFor(SucceedAssertTrue);
|
23
|
+
assertTrue(result is TestRunner);
|
24
|
+
}
|
25
|
+
|
26
|
+
[Test]
|
27
|
+
public function shouldCreateSuiteRunner():void {
|
28
|
+
var result:IRunner = factory.runnerFor(SingleSuccessSuite);
|
29
|
+
assertTrue(result is SuiteRunner);
|
30
|
+
}
|
31
|
+
|
32
|
+
[Test]
|
33
|
+
public function shouldAssignFactoryOnCreation():void {
|
34
|
+
var result:IRunner = factory.runnerFor(SingleSuccessSuite);
|
35
|
+
assertSame(factory, result.factory);
|
36
|
+
}
|
37
|
+
|
38
|
+
[Test(expects="asunit.errors.UsageError")]
|
39
|
+
public function shouldFailWhenGivenANonTestOrSuite():void {
|
40
|
+
factory.runnerFor(Sprite);
|
41
|
+
}
|
42
|
+
|
43
|
+
[Test(expects="asunit.errors.UsageError")]
|
44
|
+
public function runWithOnTestWithNoTypeDeclaration():void {
|
45
|
+
factory.runnerFor(RunWithButNoType);
|
46
|
+
}
|
47
|
+
|
48
|
+
[Test(expects="asunit.errors.UsageError")]
|
49
|
+
public function runWithOnSuiteWithNoTypeDeclaration():void {
|
50
|
+
factory.runnerFor(RunWithSuiteButNoType);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
package asunit.framework {
|
2
|
+
|
3
|
+
import asunit.framework.TestCase;
|
4
|
+
import asunit.util.Iterator;
|
5
|
+
|
6
|
+
import asunit.support.DoubleFailSuite;
|
7
|
+
import asunit.support.FailAssertEquals;
|
8
|
+
import asunit.support.FailAssertTrue;
|
9
|
+
|
10
|
+
public class SuiteIteratorTest extends TestCase {
|
11
|
+
|
12
|
+
public function SuiteIteratorTest(testMethod:String = null) {
|
13
|
+
super(testMethod);
|
14
|
+
}
|
15
|
+
|
16
|
+
public function test_countTestClasses_of_suite_class():void {
|
17
|
+
var iterator:Iterator = new SuiteIterator(DoubleFailSuite);
|
18
|
+
assertEquals(2, iterator.length);
|
19
|
+
}
|
20
|
+
|
21
|
+
public function test_accepts_non_suite_class():void {
|
22
|
+
var iterator:Iterator = new SuiteIterator(Date);
|
23
|
+
assertEquals(0, iterator.length);
|
24
|
+
}
|
25
|
+
|
26
|
+
public function test_accepts_test_class():void {
|
27
|
+
var iterator:Iterator = new SuiteIterator(FailAssertEquals);
|
28
|
+
assertEquals(1, iterator.length);
|
29
|
+
}
|
30
|
+
|
31
|
+
public function test_getTestClasses_of_suite_class():void {
|
32
|
+
var iterator:Iterator = new SuiteIterator(DoubleFailSuite);
|
33
|
+
|
34
|
+
assertEquals(2, iterator.length);
|
35
|
+
// In case the ordering is random, check that the array contains the class somewhere.
|
36
|
+
assertSame(FailAssertEquals, iterator.next());
|
37
|
+
assertSame(FailAssertTrue, iterator.next());
|
38
|
+
}
|
39
|
+
|
40
|
+
public function test_getTestClasses_on_test_class_should_return_array_with_test():void {
|
41
|
+
var iterator:Iterator = new SuiteIterator(FailAssertTrue);
|
42
|
+
|
43
|
+
assertEquals(1, iterator.length);
|
44
|
+
assertSame(FailAssertTrue, iterator.next());
|
45
|
+
}
|
46
|
+
|
47
|
+
public function test_iterator_for_non_suite_class_yields_hasNext_false():void {
|
48
|
+
var iterator:Iterator = new SuiteIterator(Date);
|
49
|
+
assertFalse(iterator.hasNext());
|
50
|
+
}
|
51
|
+
|
52
|
+
public function test_iterator_for_suite_class_with_2_tests_hasNext():void {
|
53
|
+
var iterator:Iterator = new SuiteIterator(DoubleFailSuite);
|
54
|
+
assertTrue(iterator.hasNext());
|
55
|
+
}
|
56
|
+
|
57
|
+
public function test_iterator_next():void {
|
58
|
+
var iterator:Iterator = new SuiteIterator(DoubleFailSuite);
|
59
|
+
|
60
|
+
assertSame(FailAssertEquals, iterator.next());
|
61
|
+
assertSame(FailAssertTrue, iterator.next());
|
62
|
+
|
63
|
+
assertFalse('no methods left in iterator', iterator.hasNext());
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
package asunit.framework {
|
2
|
+
|
3
|
+
public class TestCaseMock extends TestCase {
|
4
|
+
public var testMethod1Run:Boolean;
|
5
|
+
public var testMethod2Run:Boolean;
|
6
|
+
public var testMethod3Run:Boolean;
|
7
|
+
|
8
|
+
public function TestCaseMock(methodName:String = null) {
|
9
|
+
super(methodName);
|
10
|
+
}
|
11
|
+
|
12
|
+
public function testMethod1():void {
|
13
|
+
testMethod1Run = true;
|
14
|
+
}
|
15
|
+
|
16
|
+
public function testMethod2():void {
|
17
|
+
testMethod2Run = true;
|
18
|
+
}
|
19
|
+
|
20
|
+
public function testMethod3():void {
|
21
|
+
testMethod3Run = true;
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
package asunit.framework {
|
2
|
+
|
3
|
+
import asunit.framework.TestCase;
|
4
|
+
import asunit.util.Iterator;
|
5
|
+
|
6
|
+
import asunit.support.IgnoredMethod;
|
7
|
+
|
8
|
+
public class TestIteratorIgnoredMethodTest extends TestCase {
|
9
|
+
|
10
|
+
private var ignoredTest:IgnoredMethod;
|
11
|
+
private var iterator:Iterator;
|
12
|
+
|
13
|
+
public function TestIteratorIgnoredMethodTest(testMethod:String = null) {
|
14
|
+
super(testMethod);
|
15
|
+
}
|
16
|
+
|
17
|
+
protected override function setUp():void {
|
18
|
+
super.setUp();
|
19
|
+
ignoredTest = new IgnoredMethod();
|
20
|
+
}
|
21
|
+
|
22
|
+
protected override function tearDown():void {
|
23
|
+
super.tearDown();
|
24
|
+
iterator = null;
|
25
|
+
}
|
26
|
+
|
27
|
+
public function test_iterator_for_test_with_one_ignored_test_method_hasNext_true():void {
|
28
|
+
iterator = new TestIterator(ignoredTest);
|
29
|
+
assertTrue(iterator.hasNext());
|
30
|
+
}
|
31
|
+
|
32
|
+
public function test_getTestMethods_should_not_include_ignored_test():void {
|
33
|
+
var iterator:Iterator = new TestIterator(ignoredTest);
|
34
|
+
assertEquals(3, iterator.length);
|
35
|
+
}
|
36
|
+
|
37
|
+
public function test_getTestMethods_should_return_ignored_test():void {
|
38
|
+
var iterator:Iterator = new TestIterator(ignoredTest).ignoredIterator;
|
39
|
+
|
40
|
+
assertEquals(1, iterator.length);
|
41
|
+
var method:Method = iterator.next();
|
42
|
+
assertEquals('should_be_ignored', method.name);
|
43
|
+
assertTrue('method.ignore', method.ignore);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
/*
|
49
|
+
<factory type="asunit.support::IgnoredMethod">
|
50
|
+
<extendsClass type="Object"/>
|
51
|
+
<method name="runAfter" declaredBy="asunit.support::IgnoredMethod" returnType="void">
|
52
|
+
<metadata name="After"/>
|
53
|
+
</method>
|
54
|
+
<method name="should_be_ignored" declaredBy="asunit.support::IgnoredMethod" returnType="void">
|
55
|
+
<metadata name="Test"/>
|
56
|
+
<metadata name="Ignore"/>
|
57
|
+
</method>
|
58
|
+
<method name="runBefore" declaredBy="asunit.support::IgnoredMethod" returnType="void">
|
59
|
+
<metadata name="Before"/>
|
60
|
+
</method>
|
61
|
+
</factory>
|
62
|
+
*/
|
@@ -0,0 +1,50 @@
|
|
1
|
+
package asunit.framework {
|
2
|
+
|
3
|
+
import asunit.framework.TestCase;
|
4
|
+
|
5
|
+
import asunit.support.MultiMethod;
|
6
|
+
|
7
|
+
public class TestIteratorMethodByNameTest extends TestCase {
|
8
|
+
|
9
|
+
private var iterator:TestIterator;
|
10
|
+
private var multiTest:MultiMethod;
|
11
|
+
|
12
|
+
public function TestIteratorMethodByNameTest(testMethod:String = null) {
|
13
|
+
super(testMethod);
|
14
|
+
}
|
15
|
+
|
16
|
+
protected override function setUp():void {
|
17
|
+
multiTest = new MultiMethod();
|
18
|
+
}
|
19
|
+
|
20
|
+
protected override function tearDown():void {
|
21
|
+
iterator = null;
|
22
|
+
multiTest = null;
|
23
|
+
}
|
24
|
+
|
25
|
+
public function test_iterator_next_with_test_method_by_name():void {
|
26
|
+
iterator = new TestIterator(multiTest, 'stage_is_null_by_default');
|
27
|
+
checkAllNextCalls(iterator);
|
28
|
+
}
|
29
|
+
|
30
|
+
private function checkAllNextCalls(iterator:TestIterator):void {
|
31
|
+
assertSame('runBeforeClass1', iterator.next().name);
|
32
|
+
assertSame('runBeforeClass2', iterator.next().name);
|
33
|
+
|
34
|
+
assertSame('runBefore1', iterator.next().name);
|
35
|
+
assertSame('runBefore2', iterator.next().name);
|
36
|
+
assertSame('stage_is_null_by_default', iterator.next().name);
|
37
|
+
|
38
|
+
// NOTE: When a method name is provided, the teardown should
|
39
|
+
// not occur.
|
40
|
+
//assertSame('runAfter1', iterator.next().name);
|
41
|
+
//assertSame('runAfter2', iterator.next().name);
|
42
|
+
|
43
|
+
//assertSame('runAfterClass1', iterator.next().name);
|
44
|
+
//assertSame('runAfterClass2', iterator.next().name);
|
45
|
+
|
46
|
+
assertFalse('no methods left in iterator', iterator.hasNext());
|
47
|
+
}
|
48
|
+
|
49
|
+
}
|
50
|
+
}
|