2
TestFixtureSetUp
동안 구성 파일에서 가져온 데이터를 기반으로 특정 테스트를 무시하고 싶습니다. 매개 변수를 기반으로 테스트를 실행하는 것을 무시할 수 있습니까?선택적 NUnit 테스트 무시
[TestFixture]
public class MessagesTests
{
private bool isPaidAccount;
[TestFixtureSetUp]
public void Init() {
isPaidAccount = ConfigurationManager.AppSettings["IsPaidAccount"] == "True";
}
[Test]
//this test should run only if `isPaidAccount` is true
public void Message_Without_Template_Is_Sent()
{
//this tests an actual web api call.
}
}
우리가 테스트하는 계정이 유료 계정 인 경우 테스트가 잘 실행되어야하며 그렇지 않은 경우이 메서드는 예외를 throw합니다.
[Ignore(ReallyIgnore = isPaidAccount)]
의 확장이 있습니까? 아니면이 방법으로 작성하고 예를 들어 2 개의 개별 테스트 케이스를 실행해야합니다.
public void Message_Without_Template_Is_Sent()
{
if(isPaidAccount)
{
//test for return value here
}
else
{
//test for exception here
}
}
좋은 질문입니다. +1 –
테스트에서 Assert.Ignore()를 사용하십시오. – Matthew
@Matthew 그래서 그냥 테스트하기 전에 조건을 확인하고 테스트를 무시하는 것이 좋습니다. –