-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure all tests are running in CI pipeline (#645)
- Loading branch information
1 parent
f39241d
commit 4ca88f2
Showing
4 changed files
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Xunit; | ||
using Xunit.Sdk; | ||
|
||
namespace Microsoft.Azure.WebJobs.Extensions.DurableTask.Tests | ||
{ | ||
public class TestFrameworkTests | ||
{ | ||
[Fact] | ||
[Trait("Category", PlatformSpecificHelpers.TestCategory)] | ||
public void AllTestsHaveContinuousIntegrationFriendlyCategories() | ||
{ | ||
Assembly currentAssembly = Assembly.GetExecutingAssembly(); | ||
List<MethodInfo> testsMissingCategoryTrait = currentAssembly.GetTypes() | ||
.SelectMany(type => type.GetMethods()) | ||
.Where(MethodIsTest) | ||
.Where(MethodMissingCorrectCategoryTrait) | ||
.ToList(); | ||
Assert.False(testsMissingCategoryTrait.Any()); | ||
} | ||
|
||
private static bool MethodIsTest(MethodInfo method) | ||
{ | ||
var factAttribute = method.GetCustomAttribute<FactAttribute>(true); | ||
var theoryAttribute = method.GetCustomAttribute<TheoryAttribute>(true); | ||
return factAttribute != null || theoryAttribute != null; | ||
} | ||
|
||
private static bool MethodMissingCorrectCategoryTrait(MethodInfo method) | ||
{ | ||
IReadOnlyList<KeyValuePair<string, string>> methodTraits = TraitHelper.GetTraits(method); | ||
return !methodTraits.Any(TraitIsValidCategory); | ||
} | ||
|
||
private static bool TraitIsValidCategory(KeyValuePair<string, string> trait) | ||
{ | ||
return trait.Key.Equals("Category") && | ||
(trait.Value.Equals(PlatformSpecificHelpers.TestCategory) || | ||
trait.Value.Equals(PlatformSpecificHelpers.TestCategory + "_BVT") || | ||
trait.Value.Equals(PlatformSpecificHelpers.FlakeyTestCategory)); | ||
} | ||
} | ||
} |