-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom Xunit runner to allow skipping tests after they have alrea…
…dy failed, if the failure is expected (because of missing support in Jet).
- Loading branch information
Showing
14 changed files
with
544 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
test/EFCore.Jet.FunctionalTests/TestUtilities/Xunit/JetConditionalFactDiscoverer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Microsoft.EntityFrameworkCore.TestUtilities.Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace EntityFrameworkCore.Jet.FunctionalTests.TestUtilities.Xunit; | ||
|
||
public class JetConditionalFactDiscoverer : ConditionalFactDiscoverer | ||
{ | ||
public JetConditionalFactDiscoverer(IMessageSink messageSink) | ||
: base(messageSink) | ||
{ | ||
} | ||
|
||
protected override IXunitTestCase CreateTestCase( | ||
ITestFrameworkDiscoveryOptions discoveryOptions, | ||
ITestMethod testMethod, | ||
IAttributeInfo factAttribute) | ||
=> new JetConditionalFactTestCase( | ||
DiagnosticMessageSink, | ||
discoveryOptions.MethodDisplayOrDefault(), | ||
discoveryOptions.MethodDisplayOptionsOrDefault(), | ||
testMethod); | ||
} |
47 changes: 47 additions & 0 deletions
47
test/EFCore.Jet.FunctionalTests/TestUtilities/Xunit/JetConditionalFactTestCase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore.TestUtilities.Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace EntityFrameworkCore.Jet.FunctionalTests.TestUtilities.Xunit; | ||
|
||
/// <remarks> | ||
/// We cannot inherit from ConditionalFactTestCase, because it's sealed. | ||
/// </remarks> | ||
public sealed class JetConditionalFactTestCase : XunitTestCase | ||
{ | ||
[Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] | ||
public JetConditionalFactTestCase() | ||
{ | ||
} | ||
|
||
public JetConditionalFactTestCase( | ||
IMessageSink diagnosticMessageSink, | ||
TestMethodDisplay defaultMethodDisplay, | ||
TestMethodDisplayOptions defaultMethodDisplayOptions, | ||
ITestMethod testMethod, | ||
object[] testMethodArguments = null) | ||
: base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, testMethodArguments) | ||
{ | ||
} | ||
|
||
public override async Task<RunSummary> RunAsync( | ||
IMessageSink diagnosticMessageSink, | ||
IMessageBus messageBus, | ||
object[] constructorArguments, | ||
ExceptionAggregator aggregator, | ||
CancellationTokenSource cancellationTokenSource) | ||
=> await XunitTestCaseExtensions.TrySkipAsync(this, messageBus) | ||
? new RunSummary { Total = 1, Skipped = 1 } | ||
: await new JetXunitTestCaseRunner( | ||
this, | ||
DisplayName, | ||
SkipReason, | ||
constructorArguments, | ||
TestMethodArguments, | ||
messageBus, | ||
aggregator, | ||
cancellationTokenSource).RunAsync(); | ||
} |
40 changes: 40 additions & 0 deletions
40
test/EFCore.Jet.FunctionalTests/TestUtilities/Xunit/JetConditionalTheoryDiscoverer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.EntityFrameworkCore.TestUtilities.Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace EntityFrameworkCore.Jet.FunctionalTests.TestUtilities.Xunit; | ||
|
||
public class JetConditionalTheoryDiscoverer : ConditionalTheoryDiscoverer | ||
{ | ||
public JetConditionalTheoryDiscoverer(IMessageSink messageSink) | ||
: base(messageSink) | ||
{ | ||
} | ||
|
||
protected override IEnumerable<IXunitTestCase> CreateTestCasesForTheory( | ||
ITestFrameworkDiscoveryOptions discoveryOptions, | ||
ITestMethod testMethod, | ||
IAttributeInfo theoryAttribute) | ||
{ | ||
yield return new JetConditionalTheoryTestCase( | ||
DiagnosticMessageSink, | ||
discoveryOptions.MethodDisplayOrDefault(), | ||
discoveryOptions.MethodDisplayOptionsOrDefault(), | ||
testMethod); | ||
} | ||
|
||
protected override IEnumerable<IXunitTestCase> CreateTestCasesForDataRow( | ||
ITestFrameworkDiscoveryOptions discoveryOptions, | ||
ITestMethod testMethod, | ||
IAttributeInfo theoryAttribute, | ||
object[] dataRow) | ||
{ | ||
yield return new JetConditionalFactTestCase( | ||
DiagnosticMessageSink, | ||
discoveryOptions.MethodDisplayOrDefault(), | ||
discoveryOptions.MethodDisplayOptionsOrDefault(), | ||
testMethod, | ||
dataRow); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
test/EFCore.Jet.FunctionalTests/TestUtilities/Xunit/JetConditionalTheoryTestCase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore.TestUtilities.Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace EntityFrameworkCore.Jet.FunctionalTests.TestUtilities.Xunit; | ||
|
||
/// <remarks> | ||
/// We cannot inherit from ConditionalTheoryTestCase, because it's sealed. | ||
/// </remarks> | ||
public sealed class JetConditionalTheoryTestCase : XunitTheoryTestCase | ||
{ | ||
[Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] | ||
public JetConditionalTheoryTestCase() | ||
{ | ||
} | ||
|
||
public JetConditionalTheoryTestCase( | ||
IMessageSink diagnosticMessageSink, | ||
TestMethodDisplay defaultMethodDisplay, | ||
TestMethodDisplayOptions defaultMethodDisplayOptions, | ||
ITestMethod testMethod) | ||
: base(diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod) | ||
{ | ||
} | ||
|
||
public override async Task<RunSummary> RunAsync( | ||
IMessageSink diagnosticMessageSink, | ||
IMessageBus messageBus, | ||
object[] constructorArguments, | ||
ExceptionAggregator aggregator, | ||
CancellationTokenSource cancellationTokenSource) | ||
=> await XunitTestCaseExtensions.TrySkipAsync(this, messageBus) | ||
? new RunSummary { Total = 1, Skipped = 1 } | ||
: await new JetXunitTheoryTestCaseRunner( | ||
this, | ||
DisplayName, | ||
SkipReason, | ||
constructorArguments, | ||
diagnosticMessageSink, | ||
messageBus, | ||
aggregator, | ||
cancellationTokenSource) | ||
.RunAsync(); | ||
} |
74 changes: 74 additions & 0 deletions
74
test/EFCore.Jet.FunctionalTests/TestUtilities/Xunit/JetXunitTestCaseRunner.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace EntityFrameworkCore.Jet.FunctionalTests.TestUtilities.Xunit; | ||
|
||
public class JetXunitTestCaseRunner : XunitTestCaseRunner | ||
{ | ||
public JetXunitTestCaseRunner( | ||
IXunitTestCase testCase, | ||
string displayName, | ||
string skipReason, | ||
object[] constructorArguments, | ||
object[] testMethodArguments, | ||
IMessageBus messageBus, | ||
ExceptionAggregator aggregator, | ||
CancellationTokenSource cancellationTokenSource) | ||
: base( | ||
testCase, | ||
displayName, | ||
skipReason, | ||
constructorArguments, | ||
testMethodArguments, | ||
messageBus, | ||
aggregator, | ||
cancellationTokenSource) | ||
{ | ||
} | ||
|
||
protected override XunitTestRunner CreateTestRunner( | ||
ITest test, | ||
IMessageBus messageBus, | ||
Type testClass, | ||
object[] constructorArguments, | ||
MethodInfo testMethod, | ||
object[] testMethodArguments, | ||
string skipReason, | ||
IReadOnlyList<BeforeAfterTestAttribute> beforeAfterAttributes, | ||
ExceptionAggregator aggregator, | ||
CancellationTokenSource cancellationTokenSource) | ||
=> new JetXunitTestRunner( | ||
test, | ||
messageBus, | ||
testClass, | ||
constructorArguments, | ||
testMethod, | ||
testMethodArguments, | ||
skipReason, | ||
beforeAfterAttributes, | ||
new ExceptionAggregator(aggregator), | ||
cancellationTokenSource); | ||
|
||
/// <remarks> | ||
/// `TestRunner<TTestCase>.RunAsync()` is not virtual, so we need to override this method here to call our own | ||
/// `JetXunitTestRunner.RunAsync()` implementation. | ||
/// </remarks>> | ||
protected override Task<RunSummary> RunTestAsync() | ||
=> ((JetXunitTestRunner)CreateTestRunner( | ||
CreateTest(TestCase, DisplayName), | ||
MessageBus, | ||
TestClass, | ||
ConstructorArguments, | ||
TestMethod, | ||
TestMethodArguments, | ||
SkipReason, | ||
BeforeAfterAttributes, | ||
Aggregator, | ||
CancellationTokenSource)) | ||
.RunAsync(); | ||
} |
14 changes: 14 additions & 0 deletions
14
test/EFCore.Jet.FunctionalTests/TestUtilities/Xunit/JetXunitTestFramework.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace EntityFrameworkCore.Jet.FunctionalTests.TestUtilities.Xunit; | ||
|
||
public class JetXunitTestFramework : XunitTestFramework | ||
{ | ||
public JetXunitTestFramework(IMessageSink messageSink) : base(messageSink) | ||
{ | ||
} | ||
|
||
protected override ITestFrameworkDiscoverer CreateDiscoverer(IAssemblyInfo assemblyInfo) | ||
=> new JetXunitTestFrameworkDiscoverer(assemblyInfo, SourceInformationProvider, DiagnosticMessageSink); | ||
} |
Oops, something went wrong.