Skip to content

Commit

Permalink
Sunday project: update xUnit conditional test execution
Browse files Browse the repository at this point in the history
The main changes here are:
* Fix attributes that were pointing at non-existent classes
* Move conditional check execution to when the tests are running, rather than as part of discovery. This is for two reasons:
  * Code execution during discovery to, for example, attempt to connect to a database is not ideal. Discovery runs in the background and hence discovery code shouldn't do expensive or fragile things.
  * Test runners are free to discover tests without those tests having been built. For example, some test runners do discovery based on an AST. The xUnit metadata model handles this, but only if code doesn't attempt to use actual types when it shouldn't.
* Be as close to the way xUnit natively works. In other words, remove as much test execution logic as possible and extend only when really necessary.

Assembly level condition attributes are problematic for this, since they should apply to all tests in the assembly. That means that all tests need to be `ConditionalFact` or `ConditionalTheory`. This allows every test to determine if it should run, even if it's only disabled at the assembly level.

Tested with:
* Command-line runner
* VS runner
* Another one
  • Loading branch information
ajcvickers committed Jun 10, 2019
1 parent e961209 commit 17eec52
Show file tree
Hide file tree
Showing 469 changed files with 7,059 additions and 7,088 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class InternalUsageDiagnosticAnalyzerTest : DiagnosticAnalyzerTestBase
{
protected override DiagnosticAnalyzer CreateDiagnosticAnalyzer() => new InternalUsageDiagnosticAnalyzer();

[Fact]
[ConditionalFact]
public async Task No_warning_on_ef_non_internal()
=> await AssertNoDiagnostics(@"
var a = new Microsoft.EntityFrameworkCore.Infrastructure.Annotatable();
Expand All @@ -23,7 +23,7 @@ public async Task No_warning_on_ef_non_internal()

#region Namespace

[Fact]
[ConditionalFact]
public async Task Warning_on_ef_internal_namespace_invocation()
{
var (diagnostics, source) = await GetDiagnosticsAsync(@"var x = typeof(object).GetMethod(nameof(object.ToString), Type.EmptyTypes).DisplayName();");
Expand All @@ -39,7 +39,7 @@ public async Task Warning_on_ef_internal_namespace_invocation()
Assert.Equal("DisplayName", source.Substring(span.Start, span.End - span.Start));
}

[Fact]
[ConditionalFact]
public async Task Warning_on_ef_internal_namespace_instantiation()
{
var (diagnostics, source) = await GetDiagnosticsAsync(@"new CoreSingletonOptions();");
Expand All @@ -55,7 +55,7 @@ public async Task Warning_on_ef_internal_namespace_instantiation()
Assert.Equal("CoreSingletonOptions", source.Substring(span.Start, span.End - span.Start));
}

[Fact]
[ConditionalFact]
public async Task Warning_on_ef_internal_namespace_subclass()
{
var source = @"
Expand All @@ -77,7 +77,7 @@ class MyClass : Microsoft.EntityFrameworkCore.Storage.Internal.RawRelationalPara
source.Substring(span.Start, span.End - span.Start));
}

[Fact]
[ConditionalFact]
public async Task No_warning_on_ef_internal_namespace_in_same_assembly()
{
var diagnostics = await GetDiagnosticsFullSourceAsync(@"
Expand Down Expand Up @@ -106,7 +106,7 @@ public void Main(string[] args) {

#region Attribute

[Fact]
[ConditionalFact]
public async Task Warning_on_ef_internal_attribute_property_access()
{
var (diagnostics, source) = await GetDiagnosticsAsync(@"var x = Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkRelationalServicesBuilder.RelationalServices.Count;");
Expand All @@ -123,7 +123,7 @@ public async Task Warning_on_ef_internal_attribute_property_access()
Assert.Equal("RelationalServices", source.Substring(span.Start, span.End - span.Start));
}

[Fact]
[ConditionalFact]
public async Task Warning_on_ef_internal_name_instantiation()
{
var (diagnostics, source) = await GetDiagnosticsAsync(@"new Microsoft.EntityFrameworkCore.Update.UpdateSqlGeneratorDependencies(null, null);");
Expand Down
14 changes: 7 additions & 7 deletions test/EFCore.Cosmos.FunctionalTests/NestedDocumentsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public NestedDocumentsTest(ITestOutputHelper testOutputHelper)
}

// #13579
// [Fact]
// [ConditionalFact]
public virtual void Can_update_dependents()
{
using (CreateTestStore())
Expand Down Expand Up @@ -56,7 +56,7 @@ public virtual void Can_update_dependents()
}

// #13579
// [Fact]
// [ConditionalFact]
public virtual void Can_update_owner_with_dependents()
{
using (CreateTestStore())
Expand All @@ -79,7 +79,7 @@ public virtual void Can_update_owner_with_dependents()
}
}

[Fact]
[ConditionalFact]
public virtual void Can_add_collection_dependent_to_owner()
{
using (CreateTestStore())
Expand Down Expand Up @@ -174,7 +174,7 @@ public virtual void Can_add_collection_dependent_to_owner()
}

// #13559
//[Fact]
//[ConditionalFact]
public virtual void Can_update_just_dependents()
{
using (CreateTestStore())
Expand All @@ -199,7 +199,7 @@ public virtual void Can_update_just_dependents()
}
}

[Fact]
[ConditionalFact]
public virtual void Inserting_dependent_without_principal_throws()
{
using (CreateTestStore())
Expand All @@ -222,7 +222,7 @@ public virtual void Inserting_dependent_without_principal_throws()
}
}

[Fact]
[ConditionalFact]
public virtual void Can_change_nested_instance_non_derived()
{
using (CreateTestStore())
Expand Down Expand Up @@ -255,7 +255,7 @@ public virtual void Can_change_nested_instance_non_derived()
}
}

[Fact]
[ConditionalFact]
public virtual void Can_change_principal_instance_non_derived()
{
using (CreateTestStore())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.EntityFrameworkCore.Cosmos.TestUtilities;
using Xunit;

// Skip the entire assembly if cannot connect to CosmosDb
[assembly:
TestFramework(
"Microsoft.EntityFrameworkCore.TestUtilities.Xunit.ConditionalTestFramework", "Microsoft.EntityFrameworkCore.Specification.Tests")]
[assembly: CosmosDbConfiguredCondition]
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Query
{
public partial class SimpleQueryCosmosTest
{
[Theory(Skip = "See issue#13857")]
[ConditionalTheory(Skip = "See issue#13857")]
public override async Task QueryType_simple(bool isAsync)
{
await base.QueryType_simple(isAsync);
Expand All @@ -21,7 +21,7 @@ FROM root c
WHERE (c[""Discriminator""] = ""Customer"")");
}

[Theory(Skip = "See issue#13857")]
[ConditionalTheory(Skip = "See issue#13857")]
public override async Task QueryType_where_simple(bool isAsync)
{
await base.QueryType_where_simple(isAsync);
Expand All @@ -32,7 +32,7 @@ FROM root c
WHERE (c[""Discriminator""] = ""Customer"")");
}

[Fact(Skip = "See issue#13857")]
[ConditionalFact(Skip = "See issue#13857")]
public override void Query_backed_by_database_view()
{
base.Query_backed_by_database_view();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public SimpleQueryCosmosTest(
//Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}

[Fact(Skip = "See issue#13857")]
[ConditionalFact(Skip = "See issue#13857")]
public override void Auto_initialized_view_set()
{
base.Auto_initialized_view_set();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Configuration
{
public class CosmosDbContextOptionsExtensionsTests
{
[Fact]
[ConditionalFact]
public void Can_create_options_with_specified_region()
{
var regionName = CosmosRegions.EastAsia;
Expand All @@ -25,7 +25,7 @@ public void Can_create_options_with_specified_region()
/// <summary>
/// The region will be checked by the cosmosdb sdk, because the region list is not constant
/// </summary>
[Fact]
[ConditionalFact]
public void Can_create_options_with_wrong_region()
{
var regionName = "FakeRegion";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata
{
public class CosmosBuilderExtensionsTest
{
[Fact]
[ConditionalFact]
public void Default_container_name_is_used_if_not_set()
{
var modelBuilder = CreateConventionModelBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Metadata
{
public class CosmosMetadataExtensionsTest
{
[Fact]
[ConditionalFact]
public void Can_get_and_set_collection_name()
{
var modelBuilder = new ModelBuilder(new ConventionSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.ValueGenerator.Internal
{
public class IdValueGeneratorTest
{
[Fact]
[ConditionalFact]
public void Generated_ids_do_not_clash()
{
var modelBuilder = CosmosTestHelpers.Instance.CreateConventionBuilder();
Expand Down
4 changes: 2 additions & 2 deletions test/EFCore.CrossStore.FunctionalTests/DiscriminatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore
{
public class DiscriminatorTest
{
[Fact(Skip = "Tasklist#21")]
[ConditionalFact(Skip = "Tasklist#21")]
public void Can_save_entities_with_discriminators()
{
using (var context = new Context4285())
Expand Down Expand Up @@ -38,7 +38,7 @@ public void Can_save_entities_with_discriminators()
}
}

[Fact(Skip = "Tasklist#21")]
[ConditionalFact(Skip = "Tasklist#21")]
public void Can_save_entities_with_int_discriminators()
{
using (var context = new Context4285())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore
{
public class ProviderSpecificServicesTest
{
[Fact]
[ConditionalFact]
public void Throws_with_new_when_non_relational_provider_in_use()
{
var options = new DbContextOptionsBuilder<ConstructorTestContext1A>()
Expand All @@ -29,7 +29,7 @@ public void Throws_with_new_when_non_relational_provider_in_use()
}
}

[Fact]
[ConditionalFact]
public void Throws_with_add_when_non_relational_provider_in_use()
{
var appServiceProivder = new ServiceCollection()
Expand Down
2 changes: 1 addition & 1 deletion test/EFCore.Design.Tests/Design/DbContextActivatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.EntityFrameworkCore.Design
{
public class DbContextActivatorTest
{
[Fact]
[ConditionalFact]
public void CreateInstance_works()
{
var result = DbContextActivator.CreateInstance(typeof(TestContext));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Design.Internal
{
public class AppServiceProviderFactoryTest
{
[Fact]
[ConditionalFact]
public void Create_works()
{
var factory = new TestAppServiceProviderFactory(
Expand Down Expand Up @@ -43,7 +43,7 @@ private class TestService
{
}

[Fact]
[ConditionalFact]
public void Create_works_when_no_BuildWebHost()
{
var factory = new TestAppServiceProviderFactory(
Expand All @@ -59,7 +59,7 @@ private class ProgramWithoutBuildWebHost
{
}

[Fact]
[ConditionalFact]
public void Create_works_when_BuildWebHost_throws()
{
var reporter = new TestOperationReporter();
Expand Down
Loading

0 comments on commit 17eec52

Please sign in to comment.