The Artima Developer Community
Sponsored Link

Articles Forum
Borachio: Mock Objects for Scala and Android

10 replies on 1 page. Most recent reply: Jan 6, 2014 8:09 PM by lluulnw lnwpen

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 10 replies on 1 page
Darlene Wallach

Posts: 2
Nickname: darlene
Registered: May, 2006

Borachio: Mock Objects for Scala and Android Posted: Jun 30, 2011 10:00 PM
Reply to this message Reply
Advertisement
Paul Butcher discusses Borachio. Read this Artima.com article:

http://www.artima.com/scalazine/articles/borachio_mock_objects_for_scala.html

What do you think of Borachio?


Paul Butcher

Posts: 6
Nickname: 53192
Registered: Jan, 2008

Re: Borachio: Mock Objects for Scala and Android Posted: Jul 5, 2011 8:41 AM
Reply to this message Reply
For information on what's coming up in Borachio 2.0 (including mocking static methods and "new"), see:

http://www.paulbutcher.com/2011/07/power-mocking-in-scala-with-borachio/

Morgan Conrad

Posts: 307
Nickname: miata71
Registered: Mar, 2006

Re: Borachio: Mock Objects for Scala and Android Posted: Jul 6, 2011 10:59 AM
Reply to this message Reply
I have a general, novice, non-Scala question about unit testing on Android. Like, how do you do it? :-)

For example, let's say I am using android.graphics.PointF. And write a Java JUNIT test:

   public void testBah() {
      PointF aPointF = new PointF(1.2f, 3.4f);
      aPointF.offset(4.5f, 5.6f);     
      assertEquals(5.7f, aPointF.x);
      assertEquals(9.0f, aPointF.y);
   }


(More realistically, I'd be testing one of my own classes, but it uses PointF internally)

When I run it under Eclipse, you get the Stub runtime error:


java.lang.RuntimeException: Stub!
at android.graphics.PointF.<init>(PointF.java:5)


Do you have to run the tests under the Android emulator, which is really really really slow? Or is there some basic workaround?

Thanks!

Paul Butcher

Posts: 6
Nickname: 53192
Registered: Jan, 2008

Re: Borachio: Mock Objects for Scala and Android Posted: Jul 6, 2011 11:06 AM
Reply to this message Reply
Yeah, it's a problem. A big problem. Android is the most test-hostile environment I've ever had the misfortune to work with.

You probably want to check out Robolectric:

http://pivotal.github.com/robolectric/

Whether this will work for you depends on exactly what you want to test. But if it does work for you, it'll save you lots of heartache :-)

John Zabroski

Posts: 272
Nickname: zbo
Registered: Jan, 2007

Re: Borachio: Mock Objects for Scala and Android Posted: Jul 6, 2011 12:02 PM
Reply to this message Reply
Here are the basic requirements for a mocking library:

[list]
[*]Decrease coupling between tests and design. Dynamically creating mocking interfaces and mock objects, freeing the programmer from supplying hard-wired class dependencies to instantiate mock objects.
[*]Decrease coupling between tests and design. IDE Integration, supporting advanced refactorings to convert dynamically created mocks into actual interfaces provided by your API, enabling the developer to "raise to the surface" the API after prototyping and experimentation rather than providing a hook into everything
[*}Decrease coupling between tests and design. The ability to mock everything.
[/list]

What am I missing?

John Zabroski

Posts: 272
Nickname: zbo
Registered: Jan, 2007

Re: Borachio: Mock Objects for Scala and Android Posted: Jul 6, 2011 12:03 PM
Reply to this message Reply
Ah, foo. I thought Artima supported the [list] post formatting markup.

John Zabroski

Posts: 272
Nickname: zbo
Registered: Jan, 2007

Re: Borachio: Mock Objects for Scala and Android Posted: Jul 6, 2011 12:10 PM
Reply to this message Reply
Other thoughts:

Changed the name to Mockhiatto. It is a coffee reference, and perfect for a library targeted towards the Java Virtual Machine.

I think a name with the word "Mock" in it will do you a world of good in terms of marketing. .NET has this all over the place with RhinoMocks, TypeMock, and Moq. The name has to be so simple that somebody can say it out loud and at least part of the name should inform what it is for.

Again, I would also really emphasize my list above. I am not saying you can't fulfill that list above, but that you need to explicitly market your library as fulfilling the list. Old references to Martin Fowler posts aren't as valuable as they used to be. It is 2011. Really re-think how you market this stuff with the goal of having every Scala developer using your library to improve their quality assurance.

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: Borachio: Mock Objects for Scala and Android Posted: Jul 6, 2011 11:22 PM
Reply to this message Reply
> Other thoughts:
>
> Changed the name to Mockhiatto. It is a coffee reference,
> and perfect for a library targeted towards the Java
> Virtual Machine.
>
> I think a name with the word "Mock" in it will do you a
> world of good in terms of marketing. .NET has this all
> over the place with RhinoMocks, TypeMock, and Moq. The
> name has to be so simple that somebody can say it out loud
> and at least part of the name should inform what it is
> for.
>
I kind of like the name Mockhiatto. Even though it is 2011 and coffee-related names for Java things went out of style in about 1997. Maybe it has been so long that it could be cool again. Though a lot of Scala folks do know this as Borachio already.

Paul Butcher

Posts: 6
Nickname: 53192
Registered: Jan, 2008

Re: Borachio: Mock Objects for Scala and Android Posted: Jul 7, 2011 2:56 AM
Reply to this message Reply
Yeah - names are tough. We spent a lot of time trying to come up with names when I first released the project, and all the obvious ones were taken. In particular "scalamock" had been taken (although the project associated with it appeared to be moribund). So we ended up with Borachio :-)

I do like mockhiatto - although I fear that it might cause confusion about spelling (is it mockiato, mockhiato, mockiatto or mockhiatto? :-)

However, I've just noticed that scalamock.com is available again :-) The enhancements I'm currently working on are an opportunity to change the name - there are lots of other changes going to happen with the introduction of the compiler plugin etc. so perhaps this is a good time to change the name as well? What do you think?

Paul Butcher

Posts: 6
Nickname: 53192
Registered: Jan, 2008

Re: Borachio: Mock Objects for Scala and Android Posted: Jul 7, 2011 3:02 AM
Reply to this message Reply
> Really re-think
> how you market this stuff with the goal of having every
> Scala developer using your library to improve their
> quality assurance.

Thanks for the thoughtful feedback, John. I freely admit that marketing isn't my strong point :-)

As you know, "marketing" an open source project like this is more to do with word-of-mouth than anything else. With that in mind, I'd greatly appreciate any and all help with getting the word out there and explaining the benefits of this kind of testing in different ways (I suspect that no single explanation will work for all comers).

lluulnw lnwpen

Posts: 1
Nickname: lluulnw
Registered: Jan, 2014

Re: Borachio: Mock Objects for Scala and Android Posted: Jan 6, 2014 8:09 PM
Reply to this message Reply
A big problem. Android is the most test-hostile environment I've ever had the misfortune to work with.

Flat View: This topic has 10 replies on 1 page
Topic: A Brief Introduction to Rvalue References Previous Topic   Next Topic Topic: How the Use of Scala's Features Affects Compile Time

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use