tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/12884-acceptance-test-addcontextlisterner-stops-testRobotlegs: Discussion 2015-06-18T08:17:18Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/367071072015-04-30T09:09:02Z2015-04-30T09:09:02Zacceptance test - addContextListerner stops test<div><p>Please look at Joel's example for robotlegs 2 to see how to mock
a view and how to dispatch an event from a mock service:</p>
<p><a href="https://github.com/joelhooks/robotlegs-examples-FlickrGallery/blob/master/tests/robotlegs/bender/demos/imagegallery/test/cases/TestGalleryLabelMediation.as">
https://github.com/joelhooks/robotlegs-examples-FlickrGallery/blob/...</a></p>
<p>The entire project + tests:<br>
<a href="https://github.com/joelhooks/robotlegs-examples-FlickrGallery">https://github.com/joelhooks/robotlegs-examples-FlickrGallery</a></p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/367071072015-04-30T10:25:33Z2015-04-30T10:31:20Zacceptance test - addContextListerner stops test<div><p>I've just run Joel's tests and noticed that you need to make a
few changes. He used an older version of robotlegs 2.</p>
<p>For example in TestGalleryLabelMediation</p>
<p>replace this:<br>
galleryLabelMediator.setViewComponent(galleryLabel);</p>
<p>with this:<br>
galleryLabelMediator.viewComponent = galleryLabel;</p>
<p>replace this:<br>
import robotlegs.bender.extensions.eventMap.impl.EventMap;</p>
<p>with this:<br>
import robotlegs.bender.extensions.localEventMap.impl.EventMap;</p>
<p>replace this:<br>
galleryLabelMediator.eventMap = new EventMap(dispatcher);</p>
<p>with this:<br>
galleryLabelMediator.eventMap = new EventMap();</p>
<p>You need to provide the mediator with an EventDispatcher
<strong>and</strong> an EventMap</p>
<p>telltalesMediator.eventMap = new EventMap();</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/367071072015-04-30T11:33:26Z2015-04-30T11:33:26Zacceptance test - addContextListerner stops test<div><p>great thank you. It is working now!</p>
<p>Thanks for helping me all the time.</p></div>iamabletag:robotlegs.tenderapp.com,2009-10-18:Comment/367071072015-04-30T13:23:39Z2015-04-30T13:23:39Zacceptance test - addContextListerner stops test<div><p>In another acceptance test I have another problem:</p>
<p>The model is dispatching an event every 500ms. the mediator
listens for it and changes the view based on a specific value from
that model.</p>
<p>How can I test this? I tried with async tests but I don't get it
working.</p>
<p>[Before] public function setUp():void { tubeService = new
TubeService(); tubeModel = new TubeModel(); eventDispatcher = new
EventDispatcher(); digitalSpeedMediator = new
DigitalSpeedMediator(); digitalSpeedView = new DigitalSpeed();</p>
<pre>
<code> digitalSpeedMediator.view = digitalSpeedView;
digitalSpeedMediator.viewComponent = digitalSpeedView;
digitalSpeedMediator.eventDispatcher = eventDispatcher;
digitalSpeedMediator.eventMap = new EventMap();
tubeModel.eventDispatcher = eventDispatcher;
tubeService.tubeModel = tubeModel;
digitalSpeedMediator.initialize();
timer = new Timer(2000, 1);
}
[After]
public function tearDown():void
{
if (timer)
{
timer.stop();
}
timer = null;
}
[Test( async )]
public function shouldCompleteTimer():void
{
timer.addEventListener(TimerEvent.TIMER_COMPLETE, Async.asyncHandler(this, handleWin, 3000, timer, handleTimeout), false, 0, true);
timer.repeatCount = 1;
timer.start();</code>
</pre>
<p>// tubeService.vehicleSpeed = 10; }</p>
<pre>
<code> private function handleWin(e:TimerEvent):void
{
trace("erfolg");
Assert.assertEquals("10", digitalSpeedView.digitalSpeed.textField.text);
}
protected function handleTimeout(passThroughData:Object):void
{
trace("miss");
Assert.fail("Pending event timed out");
}</code>
</pre></div>iamabletag:robotlegs.tenderapp.com,2009-10-18:Comment/367071072015-04-30T15:12:01Z2015-04-30T15:12:01Zacceptance test - addContextListerner stops test<div><p>You're welcome.</p>
<blockquote>
<p>The model is dispatching an event every 500ms.</p>
</blockquote>
<p>Where are you dispatching the event??<br>
You have a timer handler (handleWin), but you're not dispatching
any event in there. So, dispatch your model's event from within a
timer handler and see what happens.</p>
<p>I think that you really need to read more about unit testing in
general, and look at examples. Keywords for the search: TDD, unit
test(ting), flexunit, testing</p>
<p>Have you tried Joel's example? You can try to use a timer with
his TestGalleryLabelMediation.</p>
<p>There are only a few discussions about unit testing on this
forum, and you should search for them and read them. But, actually,
the topic of unit testing is out of the scope of this forum....<br>
Don't expect to get an answer to all your questions about testing
;)</p>
<p>A few links here:<br>
<a href="http://knowledge.robotlegs.org/discussions/examples/24-flexunit-intergration-test-examples-and-documentation#comment_17606866">
http://knowledge.robotlegs.org/discussions/examples/24-flexunit-int...</a></p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/367071072015-05-08T08:45:15Z2015-05-08T08:45:15Zacceptance test - addContextListerner stops test<div><p>OK I got this asynch test working.</p>
<p>now I have a problem with a robotlegs service and a dependency
for the injector.</p>
<p>[Inject] public var injector:IInjector;</p>
<p>In test class how can I provide that dependency?<br>
How can I intsatiate that injector and pass it to the service?</p></div>iamabletag:robotlegs.tenderapp.com,2009-10-18:Comment/367071072015-05-11T08:50:18Z2015-05-11T08:50:18Zacceptance test - addContextListerner stops test<div><p>You need to provide the class under test with all its
dependencies. You play the role of the Injector by creating an
instance of every class that the Injector would normally inject
into it.<br>
Also look at Mockolate (links below).</p>
<p>If, for some reasons, you need the Injector itself, you have to
instantiate it like this:</p>
<p>private var injector:IInjector;<br>
injector = new RobotlegsInjector();</p>
<p>or if you created an instance of the context, you'd have access
to the injector like so:<br>
context.injector.</p>
<p>Have you already looked at the links I gave you?</p>
<p>Here, again, a few links that will help you learn TDD with
Robotlegs:</p>
<p>The Robotlegs Book + Examples with TESTS:</p>
<p>ActionScript Developer's Guide to Robotlegs<br>
<a href="http://shop.oreilly.com/product/0636920021216.do">http://shop.oreilly.com/product/0636920021216.do</a></p>
<p><a href="https://github.com/Stray/robotlegs-examples-OreillyBook">https://github.com/Stray/robotlegs-examples-OreillyBook</a></p>
<p>Mockolate: <a href="http://mockolate.org/">http://mockolate.org/</a></p>
<p>Mock example:</p>
<p><a href="https://github.com/Stray/robotlegs-examples-OreillyBook/blob/master/mosaictool/test/mosaic/controller/commands/UpdateDesignCommandTest.as">
https://github.com/Stray/robotlegs-examples-OreillyBook/blob/master...</a></p>
<p>The Robotlegs framework tests are a good inspiration:</p>
<p><a href="https://github.com/robotlegs/robotlegs-framework/tree/master/test">
https://github.com/robotlegs/robotlegs-framework/tree/master/test</a><br>
<a href="https://github.com/robotlegs/robotlegs-framework/blob/master/test/robotlegs/bender/extensions/mediatorMap/impl/MediatorFactoryTest.as">
https://github.com/robotlegs/robotlegs-framework/blob/master/test/r...</a></p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/367071072015-06-16T10:13:25Z2015-06-16T10:13:25Zacceptance test - addContextListerner stops test<div><p>Hello Ondina,</p>
<p>private var injector:IInjector;<br>
injector = new RobotlegsInjector();</p>
<p>that LOCs helped me with the problem where injector was
null.</p>
<p>Curently I try to test the factory we are discussing about in
another post and there is also the injector injected because it
should provide a singletons instance</p>
<p>public function getTelltale(lightID:String):Light<br>
{ return injector.getInstance(lightList[lightID]); }</p>
<p>I provided new RobotlegsInjector to that factory but all the
mappings are missing while running the test. Do I have to make all
the mappings again in the test case?</p></div>iamabletag:robotlegs.tenderapp.com,2009-10-18:Comment/367071072015-06-16T11:32:31Z2015-06-16T11:32:31Zacceptance test - addContextListerner stops test<div><p>Hello,</p>
<p>I gave you the example of instantiating the injector, because
you asked how to do it. I didn't say to use it like this for
testing your own classes. You would need the injector, if you would
test the framework itself or a custom extension. But, for testing
your application's classes, as I said in the first sentence of my
previous message, <strong>you</strong> have to provide the class
under test with its dependencies. <strong>You</strong> are the one
instantiating these dependencies. You don't need the injector,
because <strong>you</strong> are doing its job:<br>
var someDependency:SomeDependency = new SomeDependency();</p>
<p>I've already given you a few links.<br>
Have you looked at the examples and tests from the Robotlegs book
???</p>
<p><a href="https://github.com/Stray/robotlegs-examples-OreillyBook/tree/master/mosaictool/test">
https://github.com/Stray/robotlegs-examples-OreillyBook/tree/master...</a><br>
<a href="https://github.com/Stray/robotlegs-examples-OreillyBook/tree/master/kanbanapp/test/robotlegs/examples/kanban">
https://github.com/Stray/robotlegs-examples-OreillyBook/tree/master...</a></p>
<p>Look at the class:</p>
<p><a href="https://github.com/Stray/robotlegs-examples-OreillyBook/blob/master/kanbanapp/src/robotlegs/examples/kanban/service/SQLTaskService.as">
https://github.com/Stray/robotlegs-examples-OreillyBook/blob/master...</a></p>
<p>and then to its test:</p>
<p><a href="https://github.com/Stray/robotlegs-examples-OreillyBook/blob/master/kanbanapp/test/robotlegs/examples/kanban/service/SqlTaskServiceTest.as">
https://github.com/Stray/robotlegs-examples-OreillyBook/blob/master...</a></p>
<p>See the injections into SQLTaskService ?</p>
<pre>
<code>[Inject]
public var statusListModel:StatusListModel;
[Inject]
public var taskListModel:TaskListModel;</code>
</pre>
<p>Now, in the test class, YOU're instantiating StatusListModel and
TaskListModel YOURSELF:</p>
<pre>
<code>[Before(async)]
public function setup():void
{
taskService = new SQLTaskService();
taskService.statusListModel = new StatusListModel();
taskService.taskListModel = new TaskListModel();
initializeModels();
prepareMockolates();
}</code>
</pre></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/367071072015-06-16T11:52:25Z2015-06-16T11:52:25Zacceptance test - addContextListerner stops test<div><p>Yes I understand I have to provide the classes which were
injected.<br>
Thatswhy a provided a new RobotlegsInjector.</p>
<p>I really don't understand how I should test a method like this
without providing an injector:</p>
<p>public function getTelltale(telltaleID:String):Telltale<br>
{ return injector.getInstance(telltaleList[telltaleID]); }</p>
<p>at several points in my application I have to test if the
factory return the right object.</p>
<p>Sorry if my question is stupid.</p></div>iamabletag:robotlegs.tenderapp.com,2009-10-18:Comment/367071072015-06-16T12:26:53Z2015-06-16T12:26:53Zacceptance test - addContextListerner stops test<div><blockquote>
<p>Yes I understand I have to provide the classes which were
injected. Thatswhy a provided a new RobotlegsInjector.</p>
</blockquote>
<p>Well, obviously you didn't understand what I said :)<br>
SqlTaskServiceTest demonstrates how to provide SQLTaskService with
its dependencies.<br>
I don't know how to explain this more clearly without going into
lots of details about testing in general. I don't have time for
this, and besides the focus of this forum is not on testing. I know
from my own experience that learning how to write good tests is a
painful process, so I understand what you are going through, but I
can't help you.</p>
<blockquote>
<p>Sorry if my question is stupid.</p>
</blockquote>
<p>Your question is not stupid, but you need to read more about TDD
in general and to work with the examples that I mentioned. Maybe
reading the robotlegs book will also help you.</p>
<p>Please read about mockolate, and please read these
discussions:</p>
<p><a href="http://knowledge.robotlegs.org/discussions/problems/20-how-to-test-a-command-with-flexunit4#comment_716526">
http://knowledge.robotlegs.org/discussions/problems/20-how-to-test-...</a></p>
<p><a href="http://knowledge.robotlegs.org/discussions/questions/241-unitintegration-testing-tips-possibly-loading-a-testing-context-file#comment_2528937">
http://knowledge.robotlegs.org/discussions/questions/241-unitintegr...</a></p>
<p><a href="http://knowledge.robotlegs.org/discussions/questions/843-1st-project-setup-with-unit-testing#comment_14295403">
http://knowledge.robotlegs.org/discussions/questions/843-1st-projec...</a></p>
<p><a href="http://knowledge.robotlegs.org/discussions/questions/239-examples-of-unit-tested-applications">
http://knowledge.robotlegs.org/discussions/questions/239-examples-o...</a></p>
<p><a href="http://knowledge.robotlegs.org/discussions/questions/346-unit-testing-events#comment_3727459">
http://knowledge.robotlegs.org/discussions/questions/346-unit-testi...</a></p>
<p><a href="http://knowledge.robotlegs.org/discussions/questions/29-how-to-test-commands-and-mediators">
http://knowledge.robotlegs.org/discussions/questions/29-how-to-test...</a></p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/367071072015-06-16T13:58:53Z2015-06-16T13:59:50Zacceptance test - addContextListerner stops test<div><p>I'm so sorry. I don't want to waste your time.</p>
<p>But please lets try to solve it :(</p>
<p>my factory is injecting the IInjector which provides instances
of objects which are mapped as signleton.<br>
so the factory has the injector as a dependency, right?<br>
You told me I have to provide the dependency: Thatswhy I created a
new instance of the injector.<br>
Then the mapping is missing.</p>
<p>Now I added the mapping to the new injector and the test works
pretty well.</p>
<p>But you told me I shouldn't instantiate injector in the test
because this is done for testing the framework itself. I don't want
to test the framework. So I am a little bit confused.<br>
Is it wrong to test that factory because I am using the injector to
provide some instances?</p></div>iamabletag:robotlegs.tenderapp.com,2009-10-18:Comment/367071072015-06-16T15:09:37Z2015-06-16T15:09:37Zacceptance test - addContextListerner stops test<div><blockquote>
<p>But you told me I shouldn't instantiate injector in the test
because this is done for testing the framework itself.</p>
</blockquote>
<p>Sorry, I misunderstood your question. I thought you wanted to
instantiate the injector only in your tests to be able to provide
dependencies. Now I understand that you are injecting the injector
into the real factory class. In this case, you are right, you have
to provide the mapping as well.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/367071072015-06-16T17:41:21Z2015-06-16T17:41:21Zacceptance test - addContextListerner stops test<div><p>ok thank you for your time.</p></div>iamabletag:robotlegs.tenderapp.com,2009-10-18:Comment/367071072015-06-18T08:17:18Z2015-06-18T08:17:18Zacceptance test - addContextListerner stops test<div><p>no problem:)</p></div>Ondina D.F.