0
구체적인 인스턴스를 다형 적으로 가져 오는 추상 팩토리 메서드 (using this approach)로 추상 테스트 클래스를 만들어 추상 클래스를 단위 테스트하려고했습니다. 이런 식으로 뭔가 : xUnit.net 및 ReSharper 테스트 러너를 사용한 추상 테스트 클래스
public abstract class Base
{
public bool MyMethod()
{
return true;
}
}
public class Derived : Base {}
// Tests
public abstract class BaseTest
{
[Fact]
public void MyMethod_MakeTestFailByAssertingFalseReturn()
{
//Arrange
var instance = GetConcreteInstance();
//Act
bool result = instance.MyMethod();
//Assert
Assert.False(result);
}
protected abstract Base GetConcreteInstance();
}
public class DerivedTest : BaseTest
{
protected override Base GetConcreteInstance()
{
return new Derived();
}
}
지금까지 너무 좋아. 그러나 ReSharper 테스트 주자는이 오류를 제공합니다 :
Inconclusive: Test wasn't run
BaseTest 클래스 내의 모든 테스트에 대해. 무시되는 것조차. Visual Studio 테스트 러너로 테스트를 실행하려고 시도했지만 테스트하지 못했습니다.
'TestAttribute'를 테스트 메소드와'TestFixtureAttribute'에 클래스에 추가 했습니까? 그것들은'DerivedTest' 클래스에 상속되지 않는다는 것을 알아 두십시오. – HimBromBeere
예, 테스트 방법에'[Fact]'속성이 있습니다. 'TestFixtureAttribute'는 xUnit에서 필요하지 않습니다. 자신의 사이트에서 언급했듯이 : _xUnit.net은 테스트 클래스에 속성을 요구하지 않습니다. 어셈블리의 모든 공개 (내 보낸) 클래스에서 모든 테스트 메소드를 찾습니다. –
샘플을 실제로 정확하게 만듭니다. 예를 들어' [사실]', 그것을 넣어! –