Can I use Akka TestEventListener without polluting my test output via STDOUT?

As part of my testing, I use EventFilter and TestEventListener to listen for log messages. However, this leads to a massive thread on my command line ... which makes it very difficult to view my tests.

Code example:

it("should send a welcome message to the user", SystemFortressTest) {
  val stub = new SubFortressBuildingPermitRefTraitImplStub
  EventFilter.debug(message = "SystemFortressExchange: Received Message: SystemOutput(List(JITMP Booted))", occurrences = 1) intercept {
      stub.buildASubFortress(SystemFortressBlueprintRef)
  }
}

this code works, but it floods me with debug level data because TestEventListener prints by STDOUT by default (since it subclasses the default logger, which is just a direct STDOUT protocol)

I can collapse my own registration abstraction, which sits on top of Akka and filters messages from there before it ever gets into Akka stuff ... so it won’t pollute my command line ... but it’s terribly much if there is a similar solution which is already available.

The problem is that if I use SL4J Logger, this does not work with EventFilter.

+4
source share
3 answers

What am I doing:

akka.loglevel = DEBUG
akka.loggers = ["akka.event.slf4j.Slf4jLogger", "akka.testkit.TestEventListener"]

.. and then in my tests:

system.eventStream.publish(Mute(EventFilter.info()))
system.eventStream.publish(Mute(EventFilter.debug()))

Thus:

  • errors and warnings are reported twice (but they must be fixed anyway :))
  • Debug and informational messages are reported only through slf4j
  • you can still use eventfilters to check for specific messages (perhaps after the first ascent)

, , , , - "" . , eventstream.

+4

. TestEventListener , .

akka.loggers=["akka.testkit.TestEventListener"]
akka.loglevel = OFF

,

0

, , TestEventListener print, , , stdout. application.conf akka.loggers. ( . https://doc.akka.io/docs/akka/2.5/scala/testing.html)

, :

package mypackage
import akka.testkit.TestEventListener

class SilentTestEventListener extends TestEventListener {
  override def print(event: Any): Unit = ()
}

application.conf:

akka {
  loggers = [mypackage.SilentTestEventListener]
}

, , : , , . , , .

Another best solution would be to implement an event listener that defines its own way of processing logs instead of inheriting and modifying behavior StdOutLogger(since you expect the subclass to StdOutLoggerbe written to stdout ...), but this will require more effort than the hacker solution above. since you have to duplicate functionality TestEventListener.

0
source

All Articles