Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
VipulPathak
Posts: 81
Registered: ‎07-16-2008
My Device: Curve - 8320

Using Mock Objects on RIM API to running Unit Tests on the Computer ...

Hello,

 

Is it possible to MOCK the net_rim_api library in some way, so that the application using it can be unit tested on the development machine ?

 

I tried to use JMock to mock a class in the library, but as soon as I tried to create the mock object using the statement below, it failed :

        Mockery context = new Mockery();

        final RadioInfo radioInfoClass = context.mock(RadioInfo.class);

 

Error:

java.lang.ClassFormatError: Method <init> in class net/rim/device/api/system/RadioInfo has illegal modifiers: 0x102

 

I think, it is the format of the binary, in which the classes are packed, hence JMock is not succeeding to open the class.

 

My question is that- Is there any other way to achieve that ?  Anything, that enable unit testing on Dev machine ... If there is non ready-made library/framework, any idea to achieve it completely or partially ?

 

Regards,

 

*(Vipul)() ;
Please use plain text.
Developer
DAquilina
Posts: 587
Registered: ‎01-19-2010
My Device: BOLD 9700 OS5.0.0.x on Rogers Canada
My Carrier: Rogers

Re: Using Mock Objects on RIM API to running Unit Tests on the Computer ...

I understand that the simulators can be rather slow, but they tend to emulate the device pretty well. I can't see why mocking the library would be a better solution than that.

 

I apologize if I misunderstood what you're trying to accomplish with this -- I've never encountered programmatic mocking before.

 

Regards,

~Dom

----------------------------------------------------------------------------
chown -R us ./base
~J!NX
Please use plain text.
Developer
simon_hain
Posts: 16,199
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Using Mock Objects on RIM API to running Unit Tests on the Computer ...

there are several JUnit-derivates for blackberry, one is in development by rim itself. i don't think mocking will get you far there.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
VipulPathak
Posts: 81
Registered: ‎07-16-2008
My Device: Curve - 8320

Re: Using Mock Objects on RIM API to running Unit Tests on the Computer ...

Thanks Simon,

 

Can you point me to a couple of them ?

 

Also, Is it possible to run the unit test on the dev machine, or we must run it on Simulator/device only ?

 

Thanks,

 

*(Vipul)() ;
Please use plain text.
Developer
VipulPathak
Posts: 81
Registered: ‎07-16-2008
My Device: Curve - 8320

Re: Using Mock Objects on RIM API to running Unit Tests on the Computer ...

I initially wanted to find a way, using which the unit tests can be made running on the dev machine it self. This way, one can get the tests running after every build without deploying them on Simulator/Device.

 

Since, the original net_rim_api.jar can't be used on dev machine, I thought about mocking it.

 

*(Vipul)() ;
Please use plain text.
Developer
simon_hain
Posts: 16,199
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Using Mock Objects on RIM API to running Unit Tests on the Computer ...

sure, happy to google for you :smileyhappy:

 

http://sourceforge.net/projects/b-unittesting/

http://j2meunit.sourceforge.net/  (bunit is based on this iirc)

 

i usually only use JUnit with network code etc and don't unittest the UI.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
VipulPathak
Posts: 81
Registered: ‎07-16-2008
My Device: Curve - 8320

Re: Using Mock Objects on RIM API to running Unit Tests on the Computer ...

 


i usually only use JUnit with network code etc and don't unittest the UI.

 

Can you please elaborate on this, how you use JUnit ?

 

*(Vipul)() ;
Please use plain text.
Contributor
yerraberry
Posts: 10
Registered: ‎02-13-2010
My Device: 8820

Re: Using Mock Objects on RIM API to running Unit Tests on the Computer ...

I see what this fella is trying. Some means to unit test his code. He wants to be able to test his logic quickly, reliably and repeatably. If he has to change his code at some point in future he still wants to be able to get sleep at night. I think it is a pretty reasonable ambition. Except for, JDE is too retarded to be able to support unit testing (which is a basic prerequisite for developing any serious application that one has to live with). I know a few funny unit testing frameworks have come up attempting to fill the void. They improve the situation slightly while introducing their own complexity. I dismiss j2meunit because it helps with nothing for testing BlackBerry apps. Rest of the frameworks sound more like a hack than solution. This issue is getting old. it has been brought up gazillion times. Why RIM still doesn't provide first class support for writing unit tests. I don't get it. Are they telling us take it or leave it with their developer tools? Seriously, how do they unit test their own apps? By recruiting battalions of testers? How many development shops can afford that approach? How long will RIM be able to scale like this? Either they will go broke or end up with heaps of unmanageable buggy code (indications are that they are pretty close). How hard is it to provide a runtime that we can invoke from command line or something? How long would it take to strip the UI from the simulators? In grown up development teams skipping unit tests is heavily frowned upon. This joke of a platform does not allow us to follow one of the fundamental software engineering principles. It is about time, RIM. come on now.
Please use plain text.
Developer
VipulPathak
Posts: 81
Registered: ‎07-16-2008
My Device: Curve - 8320

Re: Using Mock Objects on RIM API to running Unit Tests on the Computer ...

Right, Ability to test the logic on dev machine is superior means of unit testing as compared to any on-device test application. Atleast RIM can provide mocked objects by themself, for unit testing purpose.

 

As far as JMunit is concerned, each testcase is derive from a MIDLet class. That means on some of the device, where only one MIDLet is allowed, one can not run multiple test cases using a Test Suite.

 

bUnit looks a straight code porting from JMUnit.

 

*(Vipul)() ;
Please use plain text.
Developer
PoojaMaheshwari
Posts: 141
Registered: ‎02-10-2010
My Device: 9500

Re: Using Mock Objects on RIM API to running Unit Tests on the Computer ...

It is high time RIM provides some unit testing framework.

Please use plain text.