How to run only one xUnit test in linqpad
Options
Hi -
Is there a way to only run one test in linqpad instead of all? Does not seem like dotnet test --filter can work in linqpad. Wondering if there is an attribute or something that can be used instead of commenting out tests. Thanks.
Comments
-
If the test is defined at the top level, you can highlight the individual method and press F5 to run just that method:
#load "xunit" void Main() { RunTests(); } [Fact] public void Test_ShouldSucceed() => Assert.True (1 + 1 == 2); [Fact] public void Test_ShouldFail() => Assert.True (1 + 1 == 3);
-
Another solution is to open the xunit query and modify the RunTests method as follows:
/// <summary>Runs all xunit tests and displays the results. To run a single test, call RunTest() instead. This method is editable in the 'xunit' query.</summary> static TestResultSummary[] RunTests (bool quietly = false, bool reportFailuresOnly = false, Func<Xunit.Abstractions.ITestCase, bool> filter = null) { using var runner = Xunit.Runners.AssemblyRunner.WithoutAppDomain (typeof (UserQuery).Assembly.Location); if (filter != null) runner.TestCaseFilter = filter; ...
Also add the following method:
static TestResultSummary[] RunTest (string methodName, bool quietly = false, bool reportFailuresOnly = false) => RunTests (quietly, reportFailuresOnly, c => c.TestMethod.Method.Name == methodName);