I am migrating stuff using .NET Framework Gherkin tests with Microsoft.VisualStudio.TestTools.UnitTesting and TechTalk.SpecFlow to .NET Core and Xunit and Xunit.Gherkin.Quick. [BeforeScenario] needed replacement with an Xunit fixture. This is basically a before-each-test trick. It looks like this:
using MyApp.MyStuff;
using System;
using Moq;
namespace MyApp.MyStuff.Tests
{
public class MyFixture : IDisposable
{
public Mock<Foo> _commit { get; private set; }
public MyFixture()
{
_commit = new Mock<Foo>();
}
public void Dispose()
{
}
}
}
I do not know that IDisposable is required. I saw it online in an example there that did database stuff honestly. Anyhow, to use the fixture in my test, I now need to give my test a constructor that did not exist like so:
private Mock<Foo> _commit;
public MyTest(MyFixture fixture)
{
_commit = fixture._commit;
}
Oh, [BeforeFeature] is also a part of the old stuff.
Addendum 4/13/2020: I could not get this to work today. Per this, perhaps I need to inherit from IClassFixture<MyFixture> instead of Feature
No comments:
Post a Comment