Js_zero
Js_zero

Reputation: 63

Could not find test case when using scalatest to test akka, what should i do to correnct it?

i a fresh of akka and scalatest, and i'm following the document of akka to learn it. But when i wonder to test the demo code like official website said, it seems do not work well.The test code is as follows.

package com.example

import akka.actor.ActorSystem
import akka.actor.testkit.typed.scaladsl.ScalaTestWithActorTestKit
import akka.testkit.TestProbe
import org.scalatest.WordSpecLike

class IotTest extends ScalaTestWithActorTestKit with WordSpecLike {

  "Iot actor system" must {
    "reply with empty reading if no temperature is known" in {
      implicit val system: ActorSystem = ActorSystem("Iot")
      val probe = TestProbe()
      val deviceActor = system.actorOf(Device.props("group", "device"))

      deviceActor.tell(Device.ReadTemperature(requestId = 42), probe.ref)
      val response = probe.expectMsgType[Device.RespondTemperature]
      response.requestId should ===(42L)
      response.value should ===(None)
    }
  }

}

when i run sbt in command-line and run testOnly IotTest command, the response is as follows

[info] Done compiling.
[info] Run completed in 9 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[info] No tests to run for Test / testOnly
[success] Total time: 3 s, completed 2019-11-1 10:33:41
sbt:akka-quickstart-scala>

the directory structure is like this.

│  build.sbt
│  list.txt
│  sbt
│  sbt.bat
├─.idea        
├─project                             
├─sbt-dist
├─src
│  ├─main
│  │  └─scala
│  │      └─com
│  │          └─example
│  │                  ActorFailureHandling.scala
│  │                  ActorHierarchyExperiments.scala
│  │                  ActorLifecycle.scala
│  │                  AkkaQuickstart.scala
│  │                  Device.scala
│  │                  DeviceGroup.scala
│  │                  DeviceGroupQuery.scala
│  │                  DeviceManager.scala
│  │                  IotApp.scala
│  │                  IotSupervisor.scala
│  │                  
│  └─test
│      └─scala
│          └─com
│              └─example
│                      AkkaQuickstartSpec.scala
│                      IotTest.scala
│                      ScalaTestIntegrationExampleSpec.scala
│                      
└─target

according to the response, no test case has been run. i was confused, and i'll appreciate it if u can do me a favor.

Upvotes: 1

Views: 174

Answers (1)

kardapoltsev
kardapoltsev

Reputation: 1088

You should use a full test name. testOnly some.package.name.TestName or testOnly *TestName.

Upvotes: 1

Related Questions