FlexUnit 4 Test Suite Problem

106 views
Skip to first unread message

Ryan Lunka

unread,
Jan 11, 2011, 11:59:32 AM1/11/11
to mockito-flex
We have a test suite of unit tests utilizing FlexUnit4. A number of
those tests use Mockito. For some reason, only one of those tests
will pass at a time. Here's what I mean...

Our test suite has the following (the * indicates use of Mockito):

Test1*
Test2*
Test3*
Test4
Test5

If I run this test suite, Test2 and Test3 will fail. If I comment out
Test1 and run again, Test3 will fail. If I comment out Test1 and
Test2, none will fail.

Note that this simple example might insinuate that the order of the
tests is the issue, but I'm (almost) positive that's not the case.
I've tried reordering the tests in my test suite to see if it makes a
difference and it doesn't. What MAY be the case is that the last test
that FlexUnit runs (which I don't think corresponds to the order they
are added to the test suite .as file), seems to be the one that
passes, and the rest fail.

It sort of seems like there is some kind of cleanup work that either
we are not doing or is not getting done on its own. Has anyone
experienced anything similar or know what's going on? I'm admittedly
pretty new to using Mockito, so bear in mind it may be something silly
that I have just missed.

Thanks a ton!

loomis

unread,
Jan 11, 2011, 2:50:27 PM1/11/11
to mockito-flex
Could you give an example of the mockito test? Especially how you
enable mockito. Also sharing info on what environment you run with
might help.

Cheers,
Kris

Ryan Lunka

unread,
Jan 11, 2011, 4:01:28 PM1/11/11
to mockito-flex
I'm using mockito-1.3 RC3 in Flex Builder 3 with FlexUnit 4. Sorry, I
guess that would help!

Here's a simple example of the kind of test I have set up...

import org.flexunit.assertThat;
import org.hamcrest.object.equalTo;
import org.mockito.integrations.flexunit4.MockitoClassRunner;
import org.mockito.integrations.given;

[RunWith("org.mockito.integrations.flexunit4.MockitoClassRunner")]
public class MockObjectTest
{
[Mock(type="test.com.adobe.ac.i3.km.mockito.MockObject")]
public var obj:MockObject;

[Test]
public function testReturnTrueAsFalse():void
{
given(obj.returnTrue()).willReturn(false);

assertThat(obj.returnTrue(), equalTo(false));
}

[Test]
public function testAbcAsXyz():void
{
given(obj.abc).willReturn("xyz");

assertThat(obj.abc, equalTo("xyz"));
}
}

I just saw an older post about an error "Please make sure you
specified a call to stub in given(...)" which are most of the errors I
get. I also get null reference errors, which I believe are a result
of the failure to mock whatever object is noted with [Mock]. I'm
currently attempting to compile and run with RC5 to see if that fixes
it. Do you know if there were any known issues fixed in more recent
releases?

Ryan Lunka

unread,
Jan 11, 2011, 4:20:43 PM1/11/11
to mockito-flex
Using RC5 does seem to help. Do you recommend upgrading to 1.4
completely, or is it significantly different (specifically with
regards to syntax and implementation)?

Kris

unread,
Jan 11, 2011, 4:26:56 PM1/11/11
to mockit...@googlegroups.com
The issue you ran into has been fixed with 1.3RC4.

The latest official release is 1.3 in 1.4 does not change much just adds functionality - however typically you should upgrade to the latest flexunit etc, some people struggle with this. Also I recommend you use MockitoRule instead of MockitoClassRunner. I'm planning on removing MockitoClassRunner completely in future. Take a look here for details:

https://bitbucket.org/loomis/mockito-flex/wiki/releases/Release1.3

Cheers,
Kris


Reply all
Reply to author
Forward
0 new messages