Cumhur,

I ran into this as well this week. After some tinkering, I came upon
a solution. I extended the FlexUnit TestCase class to make an
AsyncTestCase class from which my own test cases that make
asynchronous calls can inherit. In my case, I was testing my
services like this:

public function testSomeServiceOperation() {
var service : Object = Services.getInstance
().getService("someService");
var pendingCall = service.someOperation();
pendingCall.resultHandler = Delegate.create(this, 
CheckResult);
pendingCall.faultHandler = Delegate.create(this, 
ServiceFailed);
}

public function CheckResult(result : Object) {
...
asyncAddFailure("", "The test failed.");
...
}

public function ServiceFailed(result : Object) {
asyncAddFailure("", "The service threw a fault.");
}

>From AsyncTestCase.as:
public function asyncAddFailure(userMessage : String, 
message : String) : Void {
if (userMessage.length > 0) {
userMessage = userMessage + " - ";
}

mx.core.Application.application.testRunner.runner.treeDataPro
vider.addFailure(this, new Error(userMessage + message));

mx.core.Application.application.testRunner.testsTree.dispatch
Event({type:"change"});
}

Note that I gave my TestRunner the id of 'testRunner'.

This is probably not the best solution and I would love to see a
more elegant one. So if anyone has solved this more elegantly, I
would be interested as well. Perhaps there can be a tighter
integration between Cairngorm and FlexUnit.

Hope this helps (for what it is),
Lawrence

--- In [email protected], "Cumhur Guzel" <[EMAIL PROTECTED]> 
wrote:
> Hi folks,
> 
> 
> 
> We are using cairngorm 0.9 version and and flexunit. 
> 
> 
> 
> We would like to create a testcase which initially setting the 
input
> values up and then broadcasting an event 
> 
> 
> 
> that is creating a web service call at back-end, processing it
> resulting output from web service and updating the view.
> 
> 
> 
> Finally, we would like to test updated view object values against 
the
> expected values we know before. 
> 
> 
> 
> We have created the test case given below. 
> 
> 
> 
> (1), (2) sets the input values for test view.
> 
> (3) submits the command
> 
> (4)(5) waits for asynchronous web service call to finish. (2000
> millisecond)
> 
> (6) logger to localconnection
> 
> (7) assertion
> 
> 
> 
> This test is failing, however it is supposed to pass based on the 
Logs
> and execution values supplied.
> 
> It seems although we force this test method to stay in idle loop 
for
> 2000 milliseconds, web service call is not finished off by the mean
> time. 
> 
> (I increased the time, it did not work)
> 
> It seems problem is rooted to flash player single-threaded
> implementation, 
> 
> So would you guys recommend any workaround to overcome this 
asynchrony
> problem or something else?
> 
> 
> 
> Any help will be appreciated.
> 
> 
> 
> Code piece is given below.
> 
> 
> 
> public function testEndToEnd() {
> 
> _root.logonWindow.username.text = "tcfeu"; (1)
> 
> _root.logonWindow.password.text = "1"; (2)
> 
> EventBroadcaster.getInstance().broadcastEvent("SomeCommand");(3)
> 
> var timer:Timer = new Timer();(4)
> 
> while (!timer.wait(2000)); (5)
> 
> Log.debug("SystemTests testEndToEnd() method has been called"); (6)
> 
> assertEquals( "return value is different than expected " , 
> 
> "value" ,
> 
> valueReturningFromWebServiceCall ); (7)
> 
> }
> 
> 
> 
> 
> 
> 
> 
> Cumhur Guzel
> 
> Senior Developer
> 
> Infomedia Ltd.
> 
> Electronic Catalogues Division
> 
> Phone: +61 (0) 2 9454 1500
> 
> Direct: +61 (0) 2 9454 1709
> 
> Fax: +61 (0) 2 9454 1888
> 
> Mobile: +61 (0) 401 683 402
> 
> Website: www.infomedia.com.au
> 
> 
> 
> * This email transmission and any attachments may contain 
privileged and
> confidential information. If you are not the intended recipient 
you are
> not authorised to, read, distribute or reproduce any part of this
> transmission (including any attachments) without the prior written
> consent of the sender. If you have received this email in error, 
please
> notify the sender by email immediately.
> 
> * Opinions expressed in this email and any attachment are those of 
the
> sender and not necessarily the opinions of Infomedia.
> 
> * Please scan this email and any attachment for viruses. Infomedia 
takes
> all reasonable precautions to ensure no viruses are present in this
> email or accompanying attachments, but does not under any 
circumstance
> accept any responsibility for loss or damage caused by viruses.





Reply via email to