O'Reilly logo

Pragmatic Scala by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Mockito

It’s better to eliminate, or at least reduce dependencies, as much as possible. You can then temporarily replace essential intrinsic dependencies with stubs or mocks to get rapid feedback from unit tests.

If you’re used to EasyMock, JMock, or Mockito with JUnit, you can readily use them with ScalaTest as well. Let’s explore an example that will illustrate the use of Mockito with ScalaTest.

Tests with Functional Style

Let’s start with a series of tests for a score method that’s used in a guessing game. This method will return a total score based on the number of vowels—each vowel will receive one point whereas other characters will earn two points.

In the previous example we used a trait to hold the instance being tested. ScalaTest ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required