Using JMock on Android

How can I use JMock on Android? I have several posts that say this is not possible, but of course there is some way to do this?

It seems that the problem is that Android even recognizes the JMock jar file. So maybe there is a solution with putting banks in assets and creating a custom class loader? It sounds like a ton of trouble, but does it look like it will work?

+6
android classloader jmock
source share
1 answer

My JMock runs inside open source Android projects.

Yes: JMock code runs on the device in your hand; -)

I used:

  • JMock-2.5.1.jar
  • Repackaged hamcrest-all-1.1.jar (I will explain)
  • JMock-junit3-2.5.1.jar

See the following for the Android JMock Test http://github.com/olibye/ToneDial/blob/master/ToneDialTest/src/net/xpdeveloper/dialer/test/TestDialServiceTest.java

Here are three issues that I had to overcome:


Hamcrest Packaging

Hamcrest multiple packaging does not allow you to check the Android package.

Error in Android ADK: - Error creating final archive: duplicate entry: LICENSE.txt

Decision

unzip hamcrest-core-1.1.jar unzip hamcrest-library-1.1.jar in the same directory.

This second unboxing overwrites MANIFEST.MF and LICENCE.TXT.

zip ../ hamcrest-all-1.1.jar

First I brought it up with Steve and Nat for JMock

However, this is really a Joe packaging problem in Hamcrest (so I just posted it there;)


JUnit Packaging

The JUnit plugin in eclipse contains a subset of Hamcrest.

Solution You need to move the JUnit library down the class path after JMock in the properties of the eclipse project.


Android Packaging

JUnit v3 is part of android.jar, so you cannot use JUnit 4-style JMock tests. Annotations for us are not yet available; -)

+8
source share

All Articles