简体   繁体   English

使用Xunit运行Specflow但是给出错误nunit.framework

[英]Run Specflow with Xunit but gives error nunit.framework

I'm having a weird problem, have googled everywhere and it point out what I have already done, 我有一个奇怪的问题,到处搜索,它指出我已经做了什么,

I have a simple specflow that test a login, but after the browser is opening, i get this error. 我有一个简单的specflow测试登录,但在浏览器打开后,我收到此错误。

Test Name:  Check if Login is working
Test FullName:  SpecFlow.GeneratedTests.UITest.Smoke.Features.LoginFeature.CheckIfLoginIsWorking
Test Source:    C:\**\Login.feature : line 7
Test Outcome:   Failed
Test Duration:  0:00:02,676

Result StackTrace:  
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)
   at TechTalk.SpecFlow.UnitTestProvider.UnitTestRuntimeProviderHelper.GetAssertMethodWithFormattedMessage(String assemblyName, String typeName, String methodName)
   at TechTalk.SpecFlow.UnitTestProvider.NUnitRuntimeProvider.TestInconclusive(String message)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()
   at SpecFlow.GeneratedTests.UITest.Smoke.Features.LoginFeature.ScenarioCleanup()
   at SpecFlow.GeneratedTests.UITest.Smoke.Features.LoginFeature.CheckIfLoginIsWorking() in C:\**\Login.feature:line 17
Result Message: Could not load file or assembly 'nunit.framework' or one of its dependencies. The system cannot find the file specified.

I have also changed the app.config file to 我还将app.config文件更改为

<?xml version="1.0" encoding="utf-8"?>
<configuration>,
  <appSettings>
    <add key="xunit.diagnosticMessages" value="true"/>
  </appSettings>
  <configSections>
    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
  </configSections>
  <specFlow>
    <unitTestProvider name="xUnit"/>
    <!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
    <stepAssemblies>
      <stepAssembly assembly="SpecFlow.Assist.Dynamic" />
    </stepAssemblies>
  </specFlow>
</configuration>

The weird thing is that if i run a normal selenium test ( Not specflow ) it works directly. 奇怪的是,如果我运行正常的硒测试(非specflow),它可以直接使用。

This is also a part of the generated feature file 这也是生成的功能文件的一部分

 using TechTalk.SpecFlow;


    [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.1.0.0")]
    [System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    public partial class LoginFeature : Xunit.IClassFixture<LoginFeature.FixtureData>, System.IDisposable
    {

        private static TechTalk.SpecFlow.ITestRunner testRunner;

#line 1 "Login.feature"
#line hidden

        public LoginFeature()
        {
            this.TestInitialize();
        }

        public static void FeatureSetup()
        {
            testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner();
            TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Login", "Check if Login functionality is working\r\nas expected and see if correct username " +
                    "is poping up", ProgrammingLanguage.CSharp, ((string[])(null)));
            testRunner.OnFeatureStart(featureInfo);
        }

        public static void FeatureTearDown()
        {
            testRunner.OnFeatureEnd();
            testRunner = null;
        }

        public virtual void TestInitialize()
        {
        }

        public virtual void ScenarioTearDown()
        {
            testRunner.OnScenarioEnd();
        }

        public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
        {
            testRunner.OnScenarioStart(scenarioInfo);
        }

        public virtual void ScenarioCleanup()
        {
            testRunner.CollectScenarioErrors();
        }

        public virtual void SetFixture(LoginFeature.FixtureData fixtureData)
        {
        }

        void System.IDisposable.Dispose()
        {
            this.ScenarioTearDown();
        }

Any ideas what i can be missing? 我能错过什么想法?

Thanks in advance. 提前致谢。

I ran into this before but found that my problem was a mismatch between the feature text vs. the signature in the step, eg 我之前遇到过这个问题,但发现我的问题是特征文本与步骤中的签名不匹配,例如

Feature text: Given I have a widget id "123" 专题文字: Given I have a widget id "123"

Step signature: Given I have a widgetid "123" 步签名: Given I have a widgetid "123"

Ensuring all feature texts and step signatures matched solved the problem for me. 确保所有特征文本和步骤签名匹配解决了我的问题。

I don't know why the error was about a missing nunit dependency though, since I was using xunit. 我不知道为什么错误是关于缺少nunit依赖,因为我使用的是xunit。

This is a normal behavior since if you install Specflow nuget package it will installed based on nunit so you have to install nuget xunit for specflow 这是正常的行为,因为如果您安装Specflow nuget包它将基于nunit安装,因此您必须install nuget xunit for specflow

Install-Package SpecFlow.xUnit -Version 2.1.0

Update if you have done this try to add nunit package 如果你这样做了更新尝试添加nunit包

So, I had this happen to me. 所以,我发生了这件事。 It was a self-inflicted wound, as it turned out. 事实证明,这是一个自我伤害的伤口。

The problem was that, in a post-build event, I was copying the config file from the application under test to be the config file of the test project. 问题是,在构建后的事件中,我将配置文件从被测试的应用程序复制为测试项目的配置文件。 In the post-build event for the app, I had this line, which copies the config to the Tests folder. 在应用程序的后期构建事件中,我有这一行,它将配置复制到Tests文件夹。

copy "$(ProjectDir)"\\App.config "$(SolutionDir)"\\ReleaseImagesWreckersTests\\App.Config 复制“$(ProjectDir)”\\ App.config“$(SolutionDir)”\\ ReleaseImagesWreckersTests \\ App.Config

The config file being copied from the application under test did not have the lines in them that tell SpecFlow to use xUnit. 从被测试的应用程序复制的配置文件中没有告诉SpecFlow使用xUnit的行。 The copy was occurring before the SpecFlow tests were being built. 该副本是在构建SpecFlow测试之前发生的。 Eventually, I figured it out and added these lines to my app.config for the application (assembly) under test: 最后,我想出来并将这些行添加到我的app.config中,用于测试中的应用程序(程序集):

    <specFlow>
      <unitTestProvider name="xUnit" />
   </specFlow></configuration>

After doing that, everything worked fine. 在这之后,一切都很好。 The app under test was building successfully and then copying its config, with no specFlow section, over the top of the test assembly's config, which had the proper specFlow section before getting copied over. 被测试的应用程序正在成功构建,然后将其配置(没有specFlow部分)复制到测试程序集的配置的顶部,该配置在复制之前具有正确的specFlow部分。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Mono和Specflow - `TestCaseAttribute&#39;在名称空间`NUnit.Framework&#39;中不存在 - Mono and Specflow - `TestCaseAttribute' does not exist in the namespace `NUnit.Framework' Specflow 2.3.2:为什么Specflow使用“ Microsoft.VisualStudio.TestTools”而不是“ NUnit.Framework”生成* .cs文件 - Specflow 2.3.2: why is Specflow generating *.cs files using “Microsoft.VisualStudio.TestTools” instead of “NUnit.Framework” NUnit:无法加载程序集 nunit.framework - NUnit: Could not load assembly nunit.framework 在NUnit.Framework和Microsoft.VisualStudio.TestTools.UnitTesting命名空间中也发现了NUnit断言方法错误 - NUnit Assert method error as it is found in NUnit.Framework and Microsoft.VisualStudio.TestTools.UnitTesting namespace as well MonoGame 引用了不受支持的 nunit.framework 版本 - MonoGame references an unsupported version of nunit.framework Nunit Framework与SpecFlow框架 - Nunit Framework vs SpecFlow Framework 使用Specflow和NUnit版本3在paralel中运行测试 - Using Specflow and NUnit version 3 to run tests in paralel 打开NUnit.Framework-未定义名称空间或模块。 在F#中引用 - open NUnit.Framework - the namespace or module is not defined. Referencing in F# 尝试运行SpecFlow NUnit测试时出错:“无法访问已处置的对象。 对象名称:“ GherkinLanguageService”” - Error when attempting to run SpecFlow NUnit test: “Cannot access a disposed object. Object name: 'GherkinLanguageService'” 使用3.4及更高版本的Nunit Console运行Specflow功能文件 - Run Specflow Feature file with Nunit Console from 3.4 and above
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM