我们使用NUnit进行自动化测试,并且我们有一些必须满足的条件才能使测试运行。特别是,我们正在使用Xamarin.UITest进行移动UITesting,我们需要检查我们目前是否正在测试我们想测试的平台。不幸的是,我们没有办法使用类别来完成它。NUnit取消SetUp中的测试
我们现在要做的方式是获得我们要测试的平台列表。在[SetUp]
方法中,我们检查当前平台是否包含在该列表中,如果没有,我们中止测试。目前,我们通过让Assert.Fail()
失败来中止测试。然而,我们宁愿让测试无声地离开,没有失败和没有成功的信息,就好像它从未运行一样。这甚至是可能的,如果是这样的话,该怎么办?
下面是当前的代码:
private IList<Platform> _desiredPlatforms;
public IList<Platform> DesiredPlatforms
{
get
{
if (_desiredPlatforms == null)
{
// read from environment variable
}
return _desiredPlatforms;
}
}
[SetUp]
public void BeforeEachTest()
{
// Check if the current platform is desired
if (!DesiredPlatforms.Contains(_platform))
{
Assert.Fail("Aborting the current test as the current platform " + _platform + " is not listed in the DesiredPlatforms-list");
}
_app = AppInitializer.Instance.StartApp(_platform, _appFile);
}
嘿,感谢您的想法:)我们不能使用类别来达到这个目的,因为我们已经使用它们来对它们进行逻辑分组,但除此之外,我会毫不犹豫地尝试你说的其他事情。 – vatbub
对不起 - 它清楚地表明,在你的问题 - 我有一个金鱼的记忆! – Chris
没问题:) Inconclusive似乎为我们做了这项工作。 – vatbub