admin管理员组文章数量:1355612
I'm using a template method for tests with an abstract base class.
The abstract class is just a template with code that will be used in each derived class, and when some part of the code differs, I create an abstract method that is implemented in the derived class.
In this case, the derived classes do not have tests, only implementations of these abstract methods. You can only run tests from derived classes.
I would like to be able to enforce a skip only for one particular derived class. Is there a reasonable way to do this? Theoretically, I could insert the same tests in each derived class and skip only in one, but I don't want redundancy in the code and that is terrible solution.
Worth to mention that I'm not able to use Assert.Skip, since don't use xunit v3.
How my code works:
Example base class:
public abstract class BaseTestClass : TestBase
{
public BaseTestClass(BaseFixture fixture, ITestOutputHelper TestOutputHelper)
: base(fixture, testOutputHelper) { }
protected abstract string ExampleMethod();
[Fact]
public async Task ExampleTest()
{
//arrange
var valueSameInAllFlows1 = 1;
var valueSameInAllFlows2 = 2;
var exampleStringDifferentInEachFlow = ExampleMethod();
//act
//....
//assert
//....
}
}
First example derived class:
[Collection(DerivedFixtureA.CollectionName)]
public sealed class DerivedClassA : BaseTestClass
{
public DerivedClassA(DerivedFixtureA fixture, ITestOutputHelper testOutputHelper)
: base(fixture, testOutputHelper) { }
protected override string ExampleMethod()
{
return "derived A";
}
}
Second example derived class:
[Collection(DerivedFixtureB.CollectionName)]
public sealed class DerivedClassB : BaseTestClass
{
public DerivedClassB(DerivedFixtureB fixture, ITestOutputHelper testOutputHelper)
: base(fixture, testOutputHelper) { }
protected override string ExampleMethod()
{
return "derived B";
}
}
Let's say I only want to skip test in DerivedClassB and I want them truly skipped.
Not just if(condidtion) return;
approach.
How I'm supposed to do it?
Tried to create my own attribute, but I am not able to check the fixture from there.
本文标签: cIs there a way to skip Xunit tests only in one derived classStack Overflow
版权声明:本文标题:c# - Is there a way to skip Xunit tests only in one derived class? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744022617a2577485.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论