drewbourne / mockolate

fake chocolate, mock objects and test spies for AS3
http://mockolate.org/
MIT License
145 stars 26 forks source link

Random error from flemit #51

Open hob opened 12 years ago

hob commented 12 years ago

Drew, this is the error I emailed you about. Creating this so that you can track it publicly. The error in question seems to occur randomly and the test suite is otherwise passing:

ArgumentError: obj cannot be null
       at org.flemit.reflection::Type$/getType()[/Users/drewbourne/Workspaces/drewbourne/flemit/flemit/src/org/flemit/reflection/Type.as:447]
       at InterceptorProxyListener()[/Users/drewbourne/Workspaces/drewbourne/floxy/floxy/src/org/floxy/InterceptorProxyListener.as:18]
       at org.floxy::ProxyRepository/createWithProxyClass()[/Users/drewbourne/Workspaces/drewbourne/floxy/floxy/src/org/floxy/ProxyRepository.as:70]
       at mockolate.ingredients.floxy::FloxyMockolateFactory/createInstance()[/Users/hobspillane/workday/mockolate/mockolate/src/mockolate/ingredients/floxy/FloxyMockolateFactory.as:124]
       at mockolate.ingredients.floxy::FloxyMockolateFactory/prepareInstance()[/Users/hobspillane/workday/mockolate/mockolate/src/mockolate/ingredients/floxy/FloxyMockolateFactory.as:94]
       at global/asx.array::forEach()[/Users/drew/Development/workspace-oss-/asx/asx/src/asx/array/forEach.as:12]
       at mockolate.ingredients.floxy::FloxyMockolateFactory/prepareInstances()[/Users/hobspillane/workday/mockolate/mockolate/src/mockolate/ingredients/floxy/FloxyMockolateFactory.as:82]
       at mockolate.ingredients::Mockolatier/prepareInstances()[/Users/hobspillane/workday/mockolate/mockolate/src/mockolate/ingredients/Mockolatier.as:198]
       at mockolate.runner.statements::InjectMockInstances/evaluate()[/Users/hobspillane/workday/mockolate/mockolate/src/mockolate/runner/statements/InjectMockInstances.as:43]
       at org.flexunit.internals.runners.statements::StatementSequencer/executeStep()[E:\hudson\jobs\FlexUnit4-Flex4.1\workspace\FlexUnit4\src\org\flexunit\internals\runners\statements\StatementSequencer.as:98]
       at org.flexunit.internals.runners.statements::StatementSequencer/handleChildExecuteComplete()[E:\hudson\jobs\FlexUnit4-Flex4.1\workspace\FlexUnit4\src\org\flexunit\internals\runners\statements\StatementSequencer.as:141]
       at org.flexunit.token::AsyncTestToken/sendResult()[E:\hudson\jobs\FlexUnit4-Flex4.1\workspace\FlexUnit4\src\org\flexunit\token\AsyncTestToken.as:107]
       at Function/()[/Users/hobspillane/workday/mockolate/mockolate/src/mockolate/runner/statements/PrepareMockClasses.as:34]
       at flash.events::EventDispatcher/dispatchEventFunction()
       at flash.events::EventDispatcher/dispatchEvent()
       at Function/http://adobe.com/AS3/2006/builtin::apply()
       at SetIntervalTimer/onTimer()
       at flash.utils::Timer/_timerDispatch()
       at flash.utils::Timer/tick()
drewbourne commented 12 years ago

Hob, I've pushed some changes that may help. Care you pull from master and see if this issue pops up?

hob commented 12 years ago

Actually, I can't compile now... I was leveraging Mockolatier.prepareClassRecipies() which no longer seems to be available.

drewbourne commented 12 years ago

Mockolatier.prepareClassRecipes() is still available. Got an error or example?

hob commented 12 years ago

Here's the method that calls it:

public static function prepareMockableSystemClasses(data:MockolateRunnerData, parentToken:AsyncTestToken):void
{
    _parentToken = parentToken;
    if(mockableSystemClassesPrepared)
    {
        injectMocks(null);
    }else{
        var preparer:IEventDispatcher = data.mockolatier.prepareClassRecipes(getSystemClassRecipies());
        preparer.addEventListener(Event.COMPLETE, injectMocks);
        mockableSystemClassesPrepared = true;
    }
}

The compile error is:


Description Resource    Path    Location    Type
1195: Attempted access of inaccessible method prepareClassRecipes through a reference with static type mockolate.ingredients:Mockolatier.   TestUtil.as /trunk/[source path] test-flex/com/workday/ui/flex  line 103    Flex Problem
hob commented 12 years ago

Looks like it's under a new namespace. I'll try just switching to prepare() and see how that goes.

hob commented 12 years ago

Ok... I refactored our code to use prepare() and things are compiling now. I've also been able to get the suite to run to completion, but not every time. Now, however, I don't see the null pointer as before. Instead the suite just stalls.

drewbourne commented 12 years ago

Can you elaborate on your test setup? You appear to not be using the MockolateRule and using the runner statements in some other setup. I haven't considered that the runner statements may be used directly as part of the public API.

What sort of classes are you mocking? Lots of UIComponents and other Flex / Flash classes or mostly application code like services and models?

hob commented 12 years ago

We use MockolateRunner directly for some tests, but there are other cases where we use a new runner that I've created. That runner sub-classes MockolateRunner. Where it's declared (using RunWith()) I automatically inject mock versions of some of our core system classes (application event bus, service locator, event queue, etc..) before each test and automatically verify all of those system mocks after each test. Those classes are all declared by interface on our parsley context so none of them are terribly large.

What this buys us is greatly improved test isolation; especially where the application event bus is concerned. With this implementation, one does not have to worry about some system event dispatching from a test subject and triggering a large code path. We can simply declare an expectation on that mock application event bus in our test code without having to explicitly declare it in our tests (since its setup by our new runner) and it will get automatically verified after the test is complete.

hob commented 12 years ago

btw... If you'd like to see any of this in action and step thru the code, I'd be happy to setup a screen share. You have my email.

mscharp commented 12 years ago

Is there any update on this issue? I have a project where we are using Mockolate for and are randomly seeing this error as well. So far, we have been unable to pinpoint where/why it is happening, but its proving problematic for our continuous integration builds.

jbarrus commented 12 years ago

Submitted pull request with fix. https://github.com/drewbourne/mockolate/pull/56

jbarrus commented 12 years ago

Submitted another pull request after realizing a problem still remained.

https://github.com/drewbourne/mockolate/pull/57

hob commented 12 years ago

Well done. I'll get updated & kick off a few runs of the suite. Thanks!

gaffneykev commented 12 years ago

Nice work! :)