Your NGServiceImplTestSpec.scala file should have the following code:

class NGServicelmplTestSpec extends PlaySpec {

"The NGServiceImpl" must {

"Generate a Ramdon number" in {

val service:NGContract = new NGServiceImpl val double = service.generateDouble assert( double >= 1 )


"Generate a list of 3 Ramdon numbers" in { val service:NGContract = new NGServiceImpl val doubles = service.generateDoubleBatch(3) doubles.size mustBe 3 assert( doubles(0) >= 1 )

assert( doubles(1) >= 1 )

assert( doubles(2) >= 1 )




So here, in the preceding code, we have two methods to test the two operations that we have in our microservice. First we generate one double, and then we ask for a list of three doubles. As you can see, we just check if we get a positive double back from the service, and that's it. Since the result is not predictable, this is a good way to test it. Sometimes, even when the result is predictable, you want tests like this. Why? Because it makes the tests more reliable, and often, when we use too many hardcore values. The values could be changing and breaking our tests, and that's not cool. Let's run it on the console.

$ activator "test-only NGServicelmplTestSpec"

Here is the result that we get:

Now let's move on to the controller, and do some controller testing.

< Prev   CONTENTS   Source   Next >