Nice programing

MSTest의 글로벌 테스트 초기화 방법

nicepro 2020. 12. 29. 08:27
반응형

MSTest의 글로벌 테스트 초기화 방법


빠른 질문, 솔루션의 모든 테스트가 실행되기 전에 한 번만 실행되는 메서드를 어떻게 생성합니까?


AssemblyInitialize 특성으로 장식 된 공용 정적 메서드를 만듭니다 . 테스트 프레임 워크는 테스트 실행 당 한 번씩 Setup 메서드 를 호출 합니다.

[AssemblyInitialize()]
public static void MyTestInitialize(TestContext testContext)
{}

대한 분해 는 :

[AssemblyCleanup]
public static void TearDown() 
{}

편집하다:

또 다른 매우 중요한 세부 사항 :이 메서드가 속한 클래스는 [TestClass]. 그렇지 않으면 초기화 메서드가 실행되지 않습니다.


@driis 및 @Malice가 수락 된 답변에서 말한 것을 강조하기 위해 글로벌 테스트 이니셜 라이저 클래스는 다음과 같습니다.

namespace ThanksDriis
{
    [TestClass]
    class GlobalTestInitializer
    {
        [AssemblyInitialize()]
        public static void MyTestInitialize(TestContext testContext)
        {
            // The test framework will call this method once -BEFORE- each test run.
        }

        [AssemblyCleanup]
        public static void TearDown() 
        {
            // The test framework will call this method once -AFTER- each test run.
        }
    }
}

참조 URL : https://stackoverflow.com/questions/1427443/global-test-initialize-method-for-mstest

반응형