infinite / mockito-flex

0 stars 0 forks source link

Needed integration with funit4 - mocking an Eventdispatcher #9

Closed infinite closed 10 years ago

infinite commented 10 years ago

Needed integration with FlexUnit4.

I tried to mock an object that extends an EventDispatcher, but mockito.mock(myEventDispatcher) returns null.

infinite commented 10 years ago

From loomis on 2009-08-03 10:13:22+00:00

Can you send me the full test case where you do it? I did it several times and never seen such behavior.

infinite commented 10 years ago

From loomis on 2009-08-03 12:48:30+00:00

This seems to be flexunit 4. It has not been tested with it and I'm pretty sure it is issue with asynchronous handling of the classes generation. I'd recommend using flexunit 3 for now or figure out proper initialization of mockito. I know that the author of asmock - a basis of the mockito - is working now on flexunit4 integration so I'm not sure if such proper initialization even exists at the moment.

Because of that I'm changning bug into feature request.

infinite commented 10 years ago

From eprevot on 2009-08-03 12:58:57+00:00

Yes, sorry, it is FlexUnit 4. If you remove the extending of EventDispatcher the mock returns an Object. It returns null only when the mocked component extends EventDispatcher so I didn't think it was due to FlexUnit 4. BTW, the test I attached does not fail for me but if I run it in debug mode, I can see the mockito.mock() returns null.

infinite commented 10 years ago

From loomis on 2009-08-03 14:55:21+00:00

Debugging does not work well with asmock/mockito. There is some elaborate answer on this on our mailing list plus in the tutorial I believe.

infinite commented 10 years ago

From evrignaud on 2009-10-01 12:53:14+00:00

Hi,

I have made some modifications in the MockitoTestCase class. This to be able to support FlexUnit4 in a easy way. I have attached the FlexUnit4MockitoTestCase class. And also an sample that use it (TestMockitoWithConvientClass.as).

My opinion is that this way, the FlexUnit4 integration is not complete. A complete support would be providing a specific runner that manage in a better way all the initialisation stuff and provide the support of the [Mock] metadata. A sample of this kind of runner that is dedicated to mock-as3 can be found at this location: http://www.brianlegros.com/blog/2009/08/06/custom-test-runner-for-flexunit-4-and-mock-as3/

Regards /Etienne

infinite commented 10 years ago

From loomis on 2009-10-13 08:04:53+00:00

Thanks

infinite commented 10 years ago

From Anonymous on 2010-02-01 18:53:29+00:00

I tried using your FlexUnit4MockitoTestCase with Flash Builder 4 and its FlexUnit4 but I'm getting:

Error: No runnable methods at org.flexunit.runners::BlockFlexUnit4ClassRunner/validateInstanceMethods()[C:\Users\mlabriola\Documents\workspaces\net\digitalprimates\opensource\flexunit\FlexUnit4\src\org\flexunit\runners\BlockFlexUnit4ClassRunner.as:177] ...

FlashBuilder runs it using FlexUnitTestRunnerUI. I can attach the AS file, but can't see how to do it. I'll try to do it after submitting this comment. The file names: FlexUnitApplication.mxml and MyClass1Test.as.

droidguy

infinite commented 10 years ago

From Anonymous on 2010-02-01 19:08:04+00:00

Can't attach the files. Posting them on Google: http://docs.google.com/leaf?id=0BwA8B2umvubfZjMxNjA4ZjEtMDY5OC00YjRlLTllMDMtOTA1YWIzZjU5YjBi&hl=en

infinite commented 10 years ago

From droidguy on 2010-02-01 21:26:39+00:00

(the last 2 posts were also mine)

I have also tried to get this to work with the FlexUnit4 straight from their website, rather than using the setup offered by Flash Builder 4. So, instead of using the FlexUnitTestRunnerUI, I followed the trail pointed to by FlexUnit 4 (http://docs.flexunit.org/index.php?title=Setting_up_a_FlexUnit_4_Project). Unfortunately, I ran into problems, too. This time, I ended up with "Please make sure you specified a call to stub in given" type of error. Have no idea, if it's really my problem. I don't think so.

{{{

!actionscript

    public var myClass2Mock: MyClass2;

... myClass2Mock = mock(MyClass2, "") as MyClass2; ... given(myClass2Mock.getString()).willReturn("Spring is coming!"); }}}

I'm attaching the eclipse project with the sources. Now, that I'm logged in, I see a link to attach a file :-)

droidguy