Skip to content

Instantly share code, notes, and snippets.

@JoachimL
Created January 20, 2021 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoachimL/525ad718cdd14d4f6c6da9ed8ab17941 to your computer and use it in GitHub Desktop.
Save JoachimL/525ad718cdd14d4f6c6da9ed8ab17941 to your computer and use it in GitHub Desktop.
PoC'ing the use of shared state in Xunit tests
using System;
using System.Threading;
using Xunit;
namespace Xunit.ContextPoC
{
public class UnitTest1 : IClassFixture<Context>
{
public UnitTest1(Context ctx)
{
Ctx = ctx;
}
public Context Ctx { get; }
[Fact]
public void Test1()
{
Assert.NotNull(Ctx.JsonPayload);
}
[Fact]
public void Test2()
{
Assert.NotNull(Ctx.JsonPayload);
}
}
public class Context
{
public readonly string JsonPayload;
public Context()
{
Thread.Sleep(5000);
JsonPayload = "{'value':'1000'}";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment