Versions Compared

Key

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

...

유닛테스트는 서비스코드에 실제 사용되는 액터를 테스트해야합니다.

그리고 TestBase는 Spring Application의 초기화과정을 포함하며

여기 아티클은 Spring Boot에서 AKKA를 사용하는 방법에서 시작하였기에

http://wiki.webnori.com/display/AKKA/Spring+Boot+With+AKKA

순서상 위 내용을 먼저 알아야하며 TestTool을 셋팅하기전 위 설정을 먼저 익혀둡니다. , SpringBoot에 

AKKA를 내장하여야 합니다.


테스트 코드작성

Code Block
languagejava
themeEmacs
import akka.testkit.javadsl.TestKit;


@RunWith(SpringRunner.class)
@SpringBootTest
public class CachedbApplicationTests {	
	@Autowired
	ApplicationContext context;
	
	@Test
	public void contextLoads() {
		ActorSystem system = context.getBean(ActorSystem.class);
		SpringExtension ext = context.getBean(SpringExtension.class);		
		actorTest2(system,ext);
	}
	
	protected void actorTest2(ActorSystem system,SpringExtension ext) {
		ActorRef testActor = system.actorOf(ext.props("testActor"),"service1");		
	    new TestKit(system) {{			
			testActor.tell( "hi", getRef() );
		      // await the correct response
		    expectMsg(java.time.Duration.ofSeconds(1), "너의 메시지에 응답을함");				    	
	    }};		
	}
}

...