I'm trying to unit test a part of a project; I'm using NUnit. The targeted unit processes objects of several types, all extending a base type. I've created a generic test class on which I set the desired test types:
[TestFixture(typeof(SomeType))]
[TestFixture(typeof(SomeOtherType))]
class MyTestClass<T> where T : SomeBaseType, new()
{
[Test]
public void DoThisTest()
{
var sut = CreateSut();
var target = CreateTarget();
Assert.IsTrue(sut.Process(target));
}
[Test]
public void DoThatTest()
{
var sut = CreateSut();
var target = CreateInvalidTarget();
Assert.IsFalse(sut.IsValid(target));
}
//...
}
This creates a set of all the tests for each type set using TestFixture. For whatever reason, I have a test which only makes sense in the context of a specific type. This means that I need to either 1) use Assert.Ignore() on all other types or 2) create a different test class just for those "special" test cases.
Is there a way of opting out from a test from outside (attribute?) and specify that that particular test must not be "implemented" in certain contexts? I would like to "combine" 1) & 2) such that all the test cases are in the same file/class but some tests are only rendered/implemented/run for certain values set by TestFixture.
Aucun commentaire:
Enregistrer un commentaire