我最近开始了一个新项目并决定使用Specflow 2.1 它附带NUnit3。
目前该项目已设置且Visual Studio中的测试运行器正在正确执行,但是当我尝试从Nunit 3控制台运行程序运行相同的测试时,我收到错误。
我使用的命令是
nunit3-console.exe --labels=All --framework=net-4.5 Blah.Testing.Specflow.dll
我使用相同的程序集添加了两个本机Nunit测试,这些测试正在执行,它是一个失败的specflow测试
NUnit Console Runner 3.2.1
Copyright (C) 2016 Charlie Poole
Runtime Environment
OS Version: Microsoft Windows NT 10.0.10586.0
CLR Version: 4.0.30319.42000
Test Files
Blah.Testing.Specflow.dll
=> Blah.Testing.Specflow.MyTest.TestOne
=> Blah.Testing.Specflow.MyTest.TestTwo
=> Blah.Testing.Specflow.MyTestFeature.AddTwoNumbers
Errors and Failures
1) TearDown Error : Blah.Testing.Specflow.MyTestFeature
System.ArgumentNullException : Value cannot be null.
Parameter name: instance
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
at BoDi.ObjectContainer.RegisterInstanceAs(Object instance, Type interfaceType, String name, Boolean dispose)
at TechTalk.SpecRun.SpecFlowPlugin.Runtime.SpecRunTestRunnerManager.CreateTestRunnerInstance() in c:\TeamCity\BuildAgent\work\245a3e4d646c0875\SpecFlowPlugins\TechTalk.SpecRun.SpecFlowPlugin.2-0-0\Runtime\SpecRunTestRunnerManager.cs:line 33
at TechTalk.SpecFlow.TestRunnerManager.CreateTestRunner(Int32 threadId)
at TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(Int32 threadId)
at TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(Assembly testAssembly, Nullable`1 managedThreadId)
at Blah.Testing.Specflow.MyTestFeature.FeatureSetup() in D:\Projects\Blah\src\Testing\Blah.Testing.Specflow\MyTest.feature.cs:line 0
--TearDown
at Blah.Testing.Specflow.MyTestFeature.FeatureTearDown() in D:\Projects\Blah\src\Testing\Blah.Testing.Specflow\MyTest.feature.cs:line 0
2) Error : Blah.Testing.Specflow.MyTestFeature.AddTwoNumbers
OneTimeSetUp: System.ArgumentNullException : Value cannot be null.
Parameter name: instance
Run Settings
RuntimeFramework: net-4.5
WorkDirectory: D:\Projects\Blah\src\Testing\Blah.Testing.Specflow\bin\Dev
ImageRuntimeVersion: 4.0.30319
ImageTargetFrameworkName: .NETFramework,Version=v4.5.1
ImageRequiresX86: False
ImageRequiresDefaultAppDomainAssemblyResolver: False
NumberOfTestWorkers: 8
Test Run Summary
Overall result: Failed
Test Count: 3, Passed: 2, Failed: 1, Inconclusive: 0, Skipped: 0
Failed Tests - Failures: 0, Errors: 1, Invalid: 0
Start time: 2016-05-16 00:52:52Z
End time: 2016-05-16 00:52:53Z
Duration: 0.380 seconds
Results (nunit3) saved as TestResult.xml
我已经尝试过反映TechTalk.Specflow程序集来查看CreateTestRunnerInstance方法但是没有找到任何有用的指导我的解决方案。
生成的步骤文件代码是
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by SpecFlow (http://www.specflow.org/).
// SpecFlow Version:2.1.0.0
// SpecFlow Generator Version:2.0.0.0
//
// 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 Blah.Testing.Specflow
{
using TechTalk.SpecFlow;
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.1.0.0")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[NUnit.Framework.TestFixtureAttribute()]
[NUnit.Framework.DescriptionAttribute("MyTest")]
public partial class MyTestFeature
{
private TechTalk.SpecFlow.ITestRunner testRunner;
#line 1 "MyTest.feature"
#line hidden
[NUnit.Framework.TestFixtureSetUpAttribute()]
public virtual void FeatureSetup()
{
testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner();
TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "MyTest", "\tIn order to avoid silly mistakes\r\n\tAs a math idiot\r\n\tI want to be told the sum o" +
"f two numbers", ProgrammingLanguage.CSharp, ((string[])(null)));
testRunner.OnFeatureStart(featureInfo);
}
[NUnit.Framework.TestFixtureTearDownAttribute()]
public virtual void FeatureTearDown()
{
testRunner.OnFeatureEnd();
testRunner = null;
}
[NUnit.Framework.SetUpAttribute()]
public virtual void TestInitialize()
{
}
[NUnit.Framework.TearDownAttribute()]
public virtual void ScenarioTearDown()
{
testRunner.OnScenarioEnd();
}
public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
{
testRunner.OnScenarioStart(scenarioInfo);
}
public virtual void ScenarioCleanup()
{
testRunner.CollectScenarioErrors();
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Add two numbers")]
[NUnit.Framework.CategoryAttribute("mytag")]
public virtual void AddTwoNumbers()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Add two numbers", new string[] {
"mytag"});
#line 7
this.ScenarioSetup(scenarioInfo);
#line 8
testRunner.Given("I am on the homepage", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");
#line 9
testRunner.Then("I set the Implicit Wait to \"5000\"ms", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line 10
testRunner.Then("I take a screenshot called \"\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line hidden
this.ScenarioCleanup();
}
}
}
#pragma warning restore
#endregion
非常感谢任何帮助
答案 0 :(得分:0)
看起来,您还配置了SpecFlow + Runner(SpecRun)插件。
位于c:\ TeamCity \ BuildAgent \ work \ 245a3e4d646c0875 \ SpecFlowPlugins \ TechTalk.SpecRun.SpecFlowPlugin.2-0-0 \中的 TechTalk.SpecRun.SpecFlowPlugin .Runtime.SpecRunTestRunnerManager.CreateTestRunnerInstance() Runtime \ SpecRunTestRunnerManager.cs:第33行
请检查app.config中的插件和unittestprovider设置。 之后,重新生成所有功能代码隐藏文件(简单保存功能文件)。