현재 프로젝트에서 코드 생성이 유닛 테스트를 위해 악하다고 주장하는 클라이언트를 다루고 있습니다. 팀의 기술/평가 직원 중 일부는 매우 숙련 된 개발자이므로 놀랍습니다. 너무나도, 프로필을보고 난 후에는 (예 : 자동화) 다른 질문을하지 않는 주제에 대한 커뮤니티 의견을 구합니다.간단한 유한 상태 기계의 단위 테스트에 코드 생성을 사용하는 것이 얼마나 효과적입니까/위험할까요?
제목은 단위 테스트를 생성하기위한 코드 생성을 나타냅니다. 시나리오에 따라 다양한 범위로 수행 할 수 있습니다. 필자는이 라이브러리를 직접 작성하여 분기, 복잡성, 유지 관리 등의 측면에서 매우 단순하다고 생각합니다. 같은 것을 설명하기 위해 요약이 아래에 나열되어 있습니다.
해당 라이브러리는 두 개의 열거 형을 사용하여 가능한 목록 states
및 commands
을 확인하는 일반적인 유한 상태 시스템입니다. 명령은 추상 트랜잭션을 지정하는 데 사용되는 반면 명시 적 임의 상태는 합법적 인 한 명령없이 요청할 수 있습니다. 국가의 예로는 명령의 예 등 웨이크 업, 슬립, StartProcessing을 포함 취소 처리, WaitingForUserInput를 포함 다음과 같이
decleration은 다음과 같습니다
// Both [TState] and [TCommand] will ALWAYS be enumerations.
public abstract class StateMachineBase<TState, TCommand>: IDisposable
{
public delegate void DelegateStart (StateMachineBase<TState, TCommand> sender, EventArgs e);
public delegate void DelegateStop (StateMachineBase<TState, TCommand> sender, EventArgs e);
public delegate void DelegateTransitionRequest (StateMachineBase<TState, TCommand> sender, TransitionRequestEventArgs<TState, TCommand> e);
public delegate void DelegateTransitionComplete (StateMachineBase<TState, TCommand> sender, TransitionCompletedEventArgs<TState, TCommand> e);
public event DelegateStart OnStart = null;
public event DelegateStop OnStop = null;
public event DelegateTransitionRequest OnTransitionRequest = null;
public event DelegateTransitionComplete OnTransitionComplete = null;
private readonly object _SyncRoot = new object(); // Thread safety.
public bool Running { get; private set; }
public TState State { get; private set; }
private TCommand Command { get; set; }
private List<Transition<TState, TCommand>> AllowedTransitions { get; set; }
// Will not work if the machine is running.
protected void AddTransition (TState from, TState to, TCommand command) { ... }
public void Start() { ... }
public void Stop() { ... }
public bool CanTransit (TState state) { ... }
public bool CanTransit (TCommand command) { ... }
public bool Request (TState state) { ... }
public bool Request (TCommand command) { ... }
}
나는 경우에 사용하는 것을 깨닫게 않습니다 코드 생성은 단위 테스트를 작성하는 목적을 무효화시킬 수 있지만 많은 개발자가 특정 시나리오에서이를 사용하게 될 것이라고 확신합니다. 나는 도서관을 직접 작성했다면, 직접 또는 반성하여 단위 테스트를 할 수 있어야한다고 생각합니다.
이 경우 코드 생성을 사용하는 것이 현명한가요? 그렇지 않다면 의도하지 않은 결과가 무엇을 간과 할 수 있습니까?