lundi 28 décembre 2015

akka: test for a message modulo some fields

In the akka application I am currently testing, I have come across a certain pattern: I want to test that a TestProbe has received a certain message, modulo some fields.

For example, if the message was:

UserInfo(username: String, score: Int, timestamp: String)

then I might want to test the username and score are as expected, but not care at what time the message was received.

Currently I would write like something like this:

...

testProbe.expectMsgPF() {
  case UserInfo(`username`, `score`, _) =>
}

How could the test probe class be extended so that something like this might be written instead?

testProbe.expectApproxMsg(UserInfo(`username`, `score`, _))

In addition to shortening my code, I'm hoping an answer to this question will further my understanding of the Scala programming language.

Aucun commentaire:

Enregistrer un commentaire