Skip to content

Instantly share code, notes, and snippets.

@Stray
Created October 14, 2010 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stray/626320 to your computer and use it in GitHub Desktop.
Save Stray/626320 to your computer and use it in GitHub Desktop.
// I started to notice that my test count was increasing exponentially.
// So I placed a trace in the 'startTest' func of asunit.framework.TestResult (line 120)
public function startTest(test:Test):void {
var count:int = test.countTestCases();
fRunTests += count;
trace("startTest: " + test + " => " + count + " : " + fRunTests);
var len:uint = fListeners.length;
var item:TestListener;
for(var i:uint; i < len; i++) {
item = TestListener(fListeners[i]);
item.startTest(test);
}
}
// this showed up that startTest is being re-run
// with the test function as the value of 'test' coming through,
// where my tests have a deferred 'run' due to using mocking:
override public function run():void {
var mockolateMaker:IEventDispatcher = prepare(ISomeInterface);
mockolateMaker.addEventListener(Event.COMPLETE, prepareCompleteHandler, false, 0, true);
}
private function prepareCompleteHandler(e:Event):void {
super.run();
}
If I run only the SampleATest it is as I expect:
[trace] startTest: com.newloop.experiments.asunit::SampleATest => 3 : 3
[trace] AsUnit 3.0 by Luke Bayes and Ali Mills
[trace]
[trace] Flash Player version: MAC 10,0,32,18
[trace]
[trace] ...
[trace]
[trace] Time: 0.739
[trace]
[trace] OK (3 tests)
If I run 3 tests all with mocking I get repetitions (note that the repetitions are also incrementing the test count):
(Note that SampleATest includes a simple async test).
[trace] startTest: com.newloop.experiments.asunit::SampleATest => 3 : 3
[trace] startTest: com.newloop.experiments.asunit::SampleATest.testInstantiated() => 3 : 6
[trace] startTest: com.newloop.experiments.asunit::SampleBTest => 2 : 8
[trace] startTest: com.newloop.experiments.asunit::SampleATest.testInstantiated() => 3 : 11
[trace] startTest: com.newloop.experiments.asunit::SampleBTest.testInstantiated() => 2 : 13
[trace] startTest: com.newloop.experiments.asunit::SampleCTest => 2 : 15
[trace] AsUnit 3.0 by Luke Bayes and Ali Mills
[trace]
[trace] Flash Player version: MAC 10,0,32,18
[trace]
[trace] ...............
[trace]
[trace] Time: 0.795
[trace]
[trace] OK (15 tests)
If I remove the deferred instantiation from SampleBTest, I get less repetition:
[trace] startTest: com.newloop.experiments.asunit::SampleATest => 3 : 3
[trace] startTest: com.newloop.experiments.asunit::SampleBTest => 2 : 5
[trace] startTest: com.newloop.experiments.asunit::SampleATest.testInstantiated() => 3 : 8
[trace] startTest: com.newloop.experiments.asunit::SampleCTest => 2 : 10
[trace] AsUnit 3.0 by Luke Bayes and Ali Mills
[trace]
[trace] Flash Player version: MAC 10,0,32,18
[trace]
[trace] ..........
[trace]
[trace] Time: 0.796
[trace]
[trace] OK (10 tests)
If I add another non-deferred test in the middle, I get a different repetition:
[trace] startTest: com.newloop.experiments.asunit::SampleATest => 3 : 3
[trace] startTest: com.newloop.experiments.asunit::SampleBaTest => 2 : 5
[trace] startTest: com.newloop.experiments.asunit::SampleBTest => 2 : 7
[trace] startTest: com.newloop.experiments.asunit::SampleATest.test_async() => 3 : 10
[trace] startTest: com.newloop.experiments.asunit::SampleCTest => 2 : 12
If I remove the async test from SampleA, I get another different repetition
[trace] startTest: com.newloop.experiments.asunit::SampleATest => 3 : 3
[trace] startTest: com.newloop.experiments.asunit::SampleBaTest => 2 : 5
[trace] startTest: com.newloop.experiments.asunit::SampleBTest => 2 : 7
[trace] startTest: com.newloop.experiments.asunit::SampleATest.testFailure() => 3 : 10
[trace] startTest: com.newloop.experiments.asunit::SampleCTest => 2 : 12
Note that all the traces have been repeated multiple times
and always come back the same for the same conditions.
@Stray
Copy link
Author

Stray commented Oct 14, 2010

All tests extend TestCase.

Should I be extending AsyncTestCase instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment