우리는 직장에서 여기에 약 6 개월 동안 플렉스를 사용하고, 나는 사용자 정의 구성 요소를 포함는 FlexUnit 테스트의 첫 배치 패턴의 종류에 따라하는 경향이 있음을 발견 : 기본적으로FlexUnit 구성 요소 테스트 패턴 : addAsync를 사용하거나 수동으로 초기화 하시겠습니까?
import mx.core.Application;
import mx.events.FlexEvent;
import flexunit.framework.TestCase;
public class CustomComponentTest extends TestCase {
private var component:CustomComponent;
public function testSomeAspect() : void {
component = new CustomComponent();
// set some properties...
component.addEventListener(FlexEvent.CREATION_COMPLETE,
addAsync(verifySomeAspect, 5000));
component.height = 0;
component.width = 0;
Application.application.addChild(component);
}
public function verifySomeAspect(event:FlexEvent) : void {
// Assert some things about component...
}
override public function tearDown() : void {
try {
if (component) {
Application.application.removeChild(component);
component = null;
}
} catch (e:Error) {
// ok to ignore
}
}
을, 당신은 필요 구성 요소가 안정적으로 확인되기 전에 구성 요소가 완전히 초기화되었는지 확인하고, Flex에서는 표시 목록에 추가 된 후에 비동기 적으로 발생합니다. 따라서 콜백 (FlexUnit의 addAsync 함수 사용)을 설정해야 상황을 알릴 수 있습니다.
import flexunit.framework.TestCase;
public class CustomComponentTest extends TestCase {
public function testSomeAspect() : void {
var component:CustomComponent = new CustomComponent();
component.initialize();
// set some properties...
component.validateProperties();
// Assert some things about component...
}
이 따라하기가 훨씬 쉽다 :
은 최근에 난 그냥 수동 그래서 지금 내 테스트를 더 같이하는 경향이, 런타임이 필요한 장소에서 당신이 호출하게 될 메소드를 호출했습니다 , 그러나 나는 조금이라도 바람 피는 것처럼 다소 느낀다. 첫 번째 경우는 현재 응용 프로그램 (단위 테스트 러너 셸 응용 프로그램)으로 슬래 밍되며 후자는 "실제"환경이 아닙니다.
다른 사람들이 이러한 상황을 어떻게 처리 할 것인지 궁금합니다.