This page is no longer maintained — Please continue to the home page at www.scala-lang.org

"Native" Scala mocking library/framework

No replies
paulbutcher
Joined: 2010-03-08,
User offline. Last seen 10 weeks 5 days ago.

Is anyone aware of a native Scala mocking framework?

I'm aware that it's possible to use various different Java mocking libraries with Scala, but:

a) Unsurprisingly, they don't handle things that Java doesn't support, such as curried functions, higher-order functions, etc.

b) For my sins, I find myself developing on Android, which none of the Java mocking libraries support (because the Dalvik VM doesn't support runtime code generation).

For these reasons, I'm tempted to start looking into doing something myself. I'm thinking about a library that will allow mocks to be specified manually rather like Google's C++ mocking framework, which looks like this:

> #include "gmock/gmock.h" // Brings in Google Mock.
> class MockTurtle : public Turtle {
> public:
> ...
> MOCK_METHOD0(PenUp, void());
> MOCK_METHOD0(PenDown, void());
> MOCK_METHOD1(Forward, void(int distance));
> MOCK_METHOD1(Turn, void(int degrees));
> MOCK_METHOD2(GoTo, void(int x, int y));
> MOCK_CONST_METHOD0(GetX, int());
> MOCK_CONST_METHOD0(GetY, int());
> };

And then possibly a compiler plugin (possibly based upon autoproxy-plugin?) which could generate this kind of mock automatically and reduce the boilerplate.

But before I do so, I'd like to make sure that there isn't already something that I could either use as-is or use as a starting point.

The only thing that I've come across that's close is the Mock trait in scala.tools.reflect, but I'm not entirely sure what its status is (or, TBH, exactly what its purpose is). Is there anything else that I should be aware of?

I'd very much welcome any advice on whether the direction I'm considering makes sense, or if there's an alternative that I should pursue.

Thanks in advance,

--
paul.butcher->msgCount++

Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?

http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: paul@paulbutcher.com
AIM: paulrabutcher
Skype: paulrabutcher

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland