Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stub web calls in Scala

I'm currently writing a wrapper of the Spotify Metadata API to learn Scala. Everything's fine and dandy but I'd like to unit test the code. To properly do this I'll need to stub the Spotify API and get consistent return values (stuff like popularity of tracks changes very frequently).

Does anybody know how to stub web calls in Scala, the JVM in general or by using some external tool I could hook up into my Maven setup?

PS I'm basically looking for something like Ruby's FakeWeb...

Thanks in advance!

like image 950
Dennis Laumen Avatar asked Nov 21 '25 18:11

Dennis Laumen


1 Answers

Sounds like you need a mocking framework to stub out the web-related calls (and layer your software appropriately to plug in either the real web framework or your mocked equivalent). JMock and Mockito both work well.

You'll need to use them in conjunction with a test framework such as Junit or TestNG. I've used all of these with Scala and they work as expected.

like image 96
Brian Agnew Avatar answered Nov 23 '25 07:11

Brian Agnew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!