I came across a problem today, I was trying to integrate AsUnit with TeamCity to setup our continuous integration system.
The problem is that AsUnit runs in the Flash/Air player and it doesn’t return any result more than visual. (At least I couldn’t find a way to return a result)
So what I thought was, I can build and run my Unit Tests through an Ant script and then, using the XMLResultPrinter, save the result on a file that will be inspected by TeamCity.
I got excited but then another problem showed up. Every time you run your unit tests you are launching a new instance of adl.exe/flashplayer.exe and that will create problems if it’s part of an automatic build on a server.
You just need to know when the Tests have finished and close the application….. easy to say difficult to implement
I could not find neither an event nor a callback fired when your unit tests (TestRunner) has finished executing. I found all the events relative to single test cases but none telling me that the Runner has finished its job.
So I had to change a bit the TestRunner class by adding a new protected method that can be overridden in your Runner class. I could have chosen to fire an Event but I didn’t see the need for the extra weight as my Runner class is the main class of the AsUnit and no one is listening for its events and also the events cannot go out side the player.
here is the change:
TestRunner.as
...
private function testCompleteHandler(event:Event):void {
var endTime:Number = getTimer();
var runTime:Number = endTime - startTime;
getPrinter().printResult(result, runTime);
onTestRunnerComplete();
}
protected function onTestRunnerComplete():void
{
//override me if you want to know when I've finished my job!
}
...
After making the change listed above I was able to run, save the result and close my unit tests runner through an Ant script.
N.B.
If you are running your unit tests using FlashPlayer and you want to close it when finished you can use
System.exit(); //thanks alecmce for the update
if you are using adl (Air) use
NativeApplication.nativeApplication.exit();
Now I just need to set up TeamCity to launch the ant script and read the result file. Hope I won’t find any other issues!
I think this calls for an asunit fork on github! Great work Simone, the results are really impressive.
I’m pretty sure System.exit can be used instead of fscommand(“quit”) in fp9+
http://Www.alecmce.com Alec McEachran
I think this calls for an asunit fork on github! Great work Simone, the results are really impressive.
I’m pretty sure System.exit can be used instead of fscommand(“quit”) in fp9+
Anonymous
Thanks Alec,
yeap I can use System.exit instead of fscommand ( legacy memory ) to close the flash player.
vizio
Thanks Alec,
yeap I can use System.exit instead of fscommand ( legacy memory ) to close the flash player.
http://none alo
How are you getting the XMLResultPrinter to output to a file? I cant seem to find any info on how to do this anywhere.
Anonymous
Hi alo,
I just modified AsUnit to be able to fire an event when the tests are all finished and pass through the xml result string.
Then I created a simple AIR app to intercept that event and write a file.
You can find my modified version of AsUnit here vizio360/asunit
The class you should look for is JUnitStyleResultPrinter.as.
Let me know how you get on.
vizio
Hi alo,
I just modified AsUnit to be able to fire an event when the tests are all finished and pass through the xml result string.
Then I created a simple AIR app to intercept that event and write a file.
You can find my modified version of AsUnit here vizio360/asunit
The class you should look for is JUnitStyleResultPrinter.as.
Let me know how you get on.
http://none alo
Ive modifed a lot of code in the as25 as im working in actionscript2 and flash 8 ( dont ask why i just have to). There just appears to be no obvious solution to my problem. All i need if an output of some sort to txt file and it will be happy days.
Anonymous
hi alo,
the last thing I can think of is making the Flash Player (Debug Version) writing the trace output on a file.
To do that you need to create a mm.cfg file in
C:Documents and Settings[yourUser]
and write the following in it:
ErrorReportingEnable=1
TraceOutputFileEnable=1
then run your swf with a Flash Player Debug Version, you can find one in the CS4 installation folder (or download one from Adobe website):
C:Program FilesAdobeAdobe Flash CS4PlayersDebug
Flash player should create a flashlog.txt file in this folder:
C:Documents and Settings[yourUser]ApplicationDataMacromediaFlash PlayerLogs
hope this helps
vizio
hi alo,
the last thing I can think of is making the Flash Player (Debug Version) writing the trace output on a file.
To do that you need to create a mm.cfg file in
C:\Documents and Settings\[yourUser]
and write the following in it:
ErrorReportingEnable=1
TraceOutputFileEnable=1
then run your swf with a Flash Player Debug Version, you can find one in the CS4 installation folder (or download one from Adobe website):
Flash player should create a flashlog.txt file in this folder:
C:\Documents and Settings\[yourUser]\ApplicationData\Macromedia\Flash Player\Logs
hope this helps
http://none alo
Hi thanks for the info. Finally got it working by setting the trace compiler option to flash mx and removing all the custom trace functions from the asunit framework. So it now ouputs directly to the flashlog.txt.
On a second note it seemed to take forever for the security options chnage to take effect.
Continuous integration with AsUnit – little issue
I came across a problem today, I was trying to integrate AsUnit with TeamCity to setup our continuous integration system.
The problem is that AsUnit runs in the Flash/Air player and it doesn’t return any result more than visual. (At least I couldn’t find a way to return a result)
So what I thought was, I can build and run my Unit Tests through an Ant script and then, using the XMLResultPrinter, save the result on a file that will be inspected by TeamCity.
I got excited but then another problem showed up. Every time you run your unit tests you are launching a new instance of adl.exe/flashplayer.exe and that will create problems if it’s part of an automatic build on a server.
You just need to know when the Tests have finished and close the application….. easy to say difficult to implement
I could not find neither an event nor a callback fired when your unit tests (TestRunner) has finished executing. I found all the events relative to single test cases but none telling me that the Runner has finished its job.
So I had to change a bit the TestRunner class by adding a new protected method that can be overridden in your Runner class. I could have chosen to fire an Event but I didn’t see the need for the extra weight as my Runner class is the main class of the AsUnit and no one is listening for its events and also the events cannot go out side the player.
here is the change:
TestRunner.as ... private function testCompleteHandler(event:Event):void { var endTime:Number = getTimer(); var runTime:Number = endTime - startTime; getPrinter().printResult(result, runTime); onTestRunnerComplete(); } protected function onTestRunnerComplete():void { //override me if you want to know when I've finished my job! } ...After making the change listed above I was able to run, save the result and close my unit tests runner through an Ant script.
N.B.
If you are running your unit tests using FlashPlayer and you want to close it when finished you can use
if you are using adl (Air) use
Now I just need to set up TeamCity to launch the ant script and read the result file. Hope I won’t find any other issues!