使用自定义标签将测试标记为不确定的SpecFlow C#

时间:2018-06-28 05:53:54

标签: c# specflow

我使用的是SpecFlow,最近在某种情况下运行,即将我的测试标记为无法确定结论的错误。

我已经编写了以下代码,但是它抛出异常,不确定我所缺少的是什么,我们将不胜感激。

 if (ScenarioContext.Current.ScenarioInfo.Tags.Any(e => e.ContainsIgnoreCase("BUG")))
            {

string tag = ScenarioContext.Current.ScenarioInfo.Tags.Where(e => 
e.ContainsIgnoreCase("BUG")).First();
                string[] bugDetails = tag.Split(':').Last().Split(',');

                if (bugDetails.Count() > 0)
                {
                    Logger.WriteError("There are Active/Related bugs for this 
scenario as below:");
                    foreach (string bugId in bugDetails)
                    {
                        Logger.WriteWarning(
                        string.Format(
                            "<b><a target=\"_blank\" href=\"http://tfs:8080/tfs/DefaultCollection/TP%20Git/_workitems?id={0}&_a=edit\"></a></b>",
                            bugId));
                    }
                }
                var unitTestRuntimeProvider = ScenarioContext.Current
                    .GetBindingInstance((typeof(IUnitTestRuntimeProvider))) 
as IUnitTestRuntimeProvider;

                if (unitTestRuntimeProvider == null)
                {
                    Logger.WriteError("ScenarioContext was not casted to IUnitTestRuntimeProvider properly.");
                }
                unitTestRuntimeProvider.TestInconclusive("Inconclusived due 
to an active bug for this scenario");

最后一行使我抛出异常,内部异常设置为null。

我想做的是将所有带有标记BUG的测试标记为不确定,并且我已在SpecFlow Framework中的AfterScenario上定义了此代码。

如有任何疑问,请通知我 谢谢

0 个答案:

没有答案
相关问题