我正在面對specflow場景測試中的問題,如下所示。specFlow錯誤:ScenarioTearDown拋出對象引用未設置爲對象的一個實例例外
1.由於未將對象引用設置爲對象的實例,因此在撕下方法中存在拋出異常。
2.雖然測試通過成功,但是導致測試失敗。
plz help。
以下是feature.cs文件
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by SpecFlow (http://www.specflow.org/).
// SpecFlow Version:1.9.2.1
// SpecFlow Generator Version:1.9.0.0
// Runtime Version:4.0.30319.18052
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
#region Designer generated code
#pragma warning disable
namespace FunctionalTest.SpecFlowScenarios.APIKeyFixtures
{
using TechTalk.SpecFlow;
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.9.2.1")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()]
public partial class CreateAPIKeyFeature
{
private static TechTalk.SpecFlow.ITestRunner testRunner;
#line 1 "CreateAPIKey.feature"
#line hidden
[Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute()]
public static void FeatureSetup(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext testContext)
{
testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner();
TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "CreateAPIKey", "", ProgrammingLanguage.CSharp, ((string[])(null)));
testRunner.OnFeatureStart(featureInfo);
}
[Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute()]
public static void FeatureTearDown()
{
testRunner.OnFeatureEnd();
testRunner = null;
}
[Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute()]
public virtual void TestInitialize()
{
if (((TechTalk.SpecFlow.FeatureContext.Current != null)
&& (TechTalk.SpecFlow.FeatureContext.Current.FeatureInfo.Title != "CreateAPIKey")))
{
Tavisca.Vexiere.FunctionalTest.SpecFlowScenarios.APIKeyFixtures.CreateAPIKeyFeature.FeatureSetup(null);
}
}
// this method is throwing the null ref exception
[Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute()]
public virtual void ScenarioTearDown()
{
testRunner.OnScenarioEnd();
}
public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
{
testRunner.OnScenarioStart(scenarioInfo);
}
public virtual void ScenarioCleanup()
{
testRunner.CollectScenarioErrors();
}
[Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()]
[Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute("CreateAPIKey_Success")]
[Microsoft.VisualStudio.TestTools.UnitTesting.TestPropertyAttribute("FeatureTitle", "CreateAPIKey")]
[Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute("createAPIKey")]
public virtual void CreateAPIKey_Success()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("CreateAPIKey_Success", new string[] {
"createAPIKey"});
#line 5
this.ScenarioSetup(scenarioInfo);
#line 7
testRunner.Given("that an Organization is already set up in Vexiere hierarchy.", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");
#line 8
testRunner.When("I want to register new APIKey for above created organization.", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
#line 9
testRunner.Then("It should create new APIKey as per requested.", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line hidden
this.ScenarioCleanup();
}
}
}
#pragma warning restore
#endregion
您可以只添加一個空檢查或try/catch/ignore塊到你的撕下方法嗎? –
這不是我的自定義代碼拋出異常,而是從abc.feature.cs文件拋出異常的SecenarioTearDown方法。 – dspatil
我看到,如果您可以將特性文件添加到問題或其鏈接,和/或生成的引發空引用異常的C#代碼 –