gpt4 book ai didi

c# - 使用 Xunit 运行 Specflow 但出现错误 nunit.framework

转载 作者:行者123 更新时间:2023-11-30 15:58:37 30 4
gpt4 key购买 nike

我遇到了一个奇怪的问题,到处搜索,它指出了我已经做过的事情,

我有一个简单的 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.

我还将 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>

奇怪的是,如果我运行正常的 Selenium 测试(不是 specflow),它会直接运行。

这也是生成的特征文件的一部分

 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();
}

有什么我可能会遗漏的想法吗?

提前致谢。

最佳答案

这是正常行为,因为如果您安装 Specflow nuget 包,它将基于 nunit 安装所以你必须为specflow安装nuget xunit

Install-Package SpecFlow.xUnit -Version 2.1.0

更新如果你这样做了尝试添加 nunit 包

关于c# - 使用 Xunit 运行 Specflow 但出现错误 nunit.framework,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42999239/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com