I’d like to add that there is value in coupling the tests: if you always use fresh probes then you won’t notice if unexpected messages trickle out of a test case after it finishes. Our Akka test suite is constructed such that each test case consumes all the expected messages, which means that extraneous ones will fail a later test case and thus be noticed.
Of course this is somewhat circumstantial, doing this as a side-effect of grouping tests together. An alternative would be to teach the testing frameworks to watch out for asynchronous failures on different threads, but that is in general not a simple thing to do. Regards, Roland 22 aug 2014 kl. 12:42 skrev Björn Antonsson <[email protected]>: > Hi Dennis, > > I was just about to suggest that. Great that you found it yourself. > > B/ > > On 22 August 2014 at 12:40:50, Dennis Vriend ([email protected]) wrote: > >> Solved I guess, this also works, use a TestProbe, no need to clear the >> queue, just create a new Probe! >> >> it should "send RequireAck and transition to state WaitingForAckTicket and >> update its state to TransactionData" in { >> val testProbe = TestProbe() >> val ticketDispenser = TestProbe() >> val fsm = TestFSMRef(new TestTicketTransaction(ticketDispenser.ref)) >> val testFsm: TestActorRef[TestTicketTransaction] = fsm >> >> testProbe.send(testFsm, GetTicketNumber("a", "b")) >> >> testProbe.expectMsg(RequireAck(10L)) >> assert(fsm.stateName == WaitingForAckTicket) >> assert(fsm.stateData == TransactionData("a", "b")) >> } >> >> >> Op vrijdag 22 augustus 2014 12:22:40 UTC+2 schreef Dennis Vriend:I have some >> test: >> >> class MyTest extends TestKit(ActorSystem("TestCluster")) with ImplicitSender >> with FlatSpecLike with BeforeAndAfterAll { >> "TicketTransaction" should "should be in Idle state and data must be >> Uninitialized when created" in { >> val ticketDispenserProbe = TestProbe() >> val fsm = TestFSMRef(new TestTicketTransaction(ticketDispenserProbe.ref)) >> val testFsm: TestActorRef[TestTicketTransaction] = fsm >> >> assert(fsm.stateName == Idle) >> assert(fsm.stateData == Uninitialized) >> clear() >> } >> >> it should "send RequireAck and transition to state WaitingForAckTicket and >> update its state to TransactionData" in { >> val ticketDispenserProbe = TestProbe() >> val fsm = TestFSMRef(new TestTicketTransaction(ticketDispenserProbe.ref)) >> val testFsm: TestActorRef[TestTicketTransaction] = fsm >> >> val transactionId = "AAA" >> val campaignId = "BBB" >> >> testFsm ! GetTicketNumber(transactionId, campaignId) >> >> expectMsg(RequireAck(10L)) >> assert(fsm.stateName == WaitingForAckTicket) >> assert(fsm.stateData == TransactionData(transactionId, campaignId)) >> clear() >> } >> } >> >> I want to clear the queue for the next test. I can not find any clear >> method, this came close: >> >> >> def clear(): Unit = { >> receiveWhile(200 milliseconds) { >> case msg @ _ => >> } >> } >> >> >> >> >> -- >> >>>>>>>>>> Read the docs: http://akka.io/docs/ >> >>>>>>>>>> Check the FAQ: >> >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user >> --- >> You received this message because you are subscribed to the Google Groups >> "Akka User List" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/akka-user. >> For more options, visit https://groups.google.com/d/optout. > -- > Björn Antonsson > Typesafe – Reactive Apps on the JVM > twitter: @bantonsson > > > -- > >>>>>>>>>> Read the docs: http://akka.io/docs/ > >>>>>>>>>> Check the FAQ: > >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html > >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user > --- > You received this message because you are subscribed to the Google Groups > "Akka User List" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/akka-user. > For more options, visit https://groups.google.com/d/optout. Dr. Roland Kuhn Akka Tech Lead Typesafe – Reactive apps on the JVM. twitter: @rolandkuhn -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
