Skip to content

Commit

Permalink
Speed up skipped tests execution
Browse files Browse the repository at this point in the history
This shortcirtuits test runs when they will be skipped, and
also avoids launching VS altogether unless at least one
test is actually executed.

Fixes #39
  • Loading branch information
kzu committed Aug 23, 2022
1 parent bca8469 commit 07a96a4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/Xunit.Vsix/VsixTestCollectionRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class VsixTestCollectionRunner : XunitTestCollectionRunner, IDisposable

_vsVersion = testCollection.VisualStudioVersion;
_rootSuffix = testCollection.RootSuffix;
_vs = new VsClient(_vsVersion, _rootSuffix, testCollection.Settings);
_vs = new LazyVsClient(() => new VsClient(_vsVersion, _rootSuffix, testCollection.Settings));
}

protected override Task<RunSummary> RunTestClassAsync(ITestClass testClass, IReflectionTypeInfo @class, IEnumerable<IXunitTestCase> testCases)
Expand All @@ -35,9 +35,28 @@ protected override Task<RunSummary> RunTestClassAsync(ITestClass testClass, IRef
Aggregator, CancellationTokenSource, CollectionFixtureMappings).RunAsync();
}

public void Dispose()
public void Dispose() => _vs.Dispose();

class LazyVsClient : IVsClient
{
_vs.Dispose();
Lazy<IVsClient> _vs;

public LazyVsClient(Func<IVsClient> factory) => _vs = new Lazy<IVsClient>(factory);

public void Dispose()
{
if (_vs.IsValueCreated)
_vs.Value.Dispose();
}

public void Recycle()
{
if (_vs.IsValueCreated)
_vs.Value.Recycle();
}

public Task<RunSummary> RunAsync(VsixTestCase testCase, IMessageBus messageBus, ExceptionAggregator aggregator)
=> _vs.Value.RunAsync(testCase, messageBus, aggregator);
}
}
}
3 changes: 3 additions & 0 deletions src/Xunit.Vsix/VsixTestMethodRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public VsixTestMethodRunner(IVsClient vsClient, ITestMethod testMethod, IReflect

protected override Task<RunSummary> RunTestCaseAsync(IXunitTestCase testCase)
{
if (testCase.SkipReason != null)
return base.RunTestCaseAsync(testCase);

if (!CancellationTokenSource.IsCancellationRequested)
return _vsClient.RunAsync((VsixTestCase)testCase, MessageBus, Aggregator);
else
Expand Down

0 comments on commit 07a96a4

Please sign in to comment.