Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

기존 VS 유닛 테스트기와 연동되어 사용이 가능해집니다.


Image Modified

-실제 메시지 처리에 대한 유효검사가 용이해집니다.

-여러가지 가상의 환경을 셋팅하여 AKKA의

기능에관련된 메시징 기능 체크가 가능합니다.

-이것이 가능한 이유는 기본 유닛테스트 클래스가

액터기반으로 작동이 되기때문입니다.


설치(기존 유닛 테스트에 추가 설치)


사용예

Code Block
languagec#
themeEmacs
linenumberstrue
using ServiceA.STUDY;

using Akka.TestKit.VsTest;

namespace AkkaTest
{
    [TestClass]
    public class UnitTest1 : TestKit //TestKit을 상속받습니다.
    {
        [TestMethod]
        public void TestMethod1()  //기본 유닛 테스트기
        {
            using (ActorSystem actorSystem = ActorSystem.Create("ServiceA"))
            {
                IActorRef myActor = actorSystem.ActorOf<BasicActor>("myactor");
                Props watchProps = WatchActor.Props(myActor);
                IActorRef watcher = actorSystem.ActorOf(watchProps, "watcher");
                var result = myActor.Ask("나는 살아있다.").Result;
                actorSystem.Stop(myActor); //myActor를 임의로 Stop하여, watcher가 종료를감시한는지 체크
                myActor.GracefulStop(TimeSpan.FromSeconds(10)).Wait();  //생성한 Actor를 안전하게 종료시킨다.
            }            
        }

        [TestMethod]
        public void TestMethod2()  //Akka Tookit을 이용한 유닛테스트, 테스트기에 테스트를 할수 있는 액터가 추가됨
        {
            //실제 서비스코드와는 다른 패턴이기때문에, 학습용으로는 적당하지 않습니다.
            var myActor = this.Sys.ActorOf<MyActor>("myActor");  //MyActor는 사용자의 메시지에 Re:+ 를 붙여 응답합니다.
            var probe = this.CreateTestProbe();
            myActor.Tell("Hello", this.TestActor);
            ExpectMsg("Re:Hello", TimeSpan.FromSeconds(1));            
        }

    }
}

...