-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2234 from andy840119/add-check-test-assert-usage
Add more strict check about test assert usage and naming.
- Loading branch information
Showing
7 changed files
with
129 additions
and
46 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
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using ArchUnitNET.Domain; | ||
using ArchUnitNET.Domain.Extensions; | ||
using NUnit.Framework; | ||
using osu.Framework.Testing; | ||
|
@@ -32,23 +34,10 @@ public void CheckTestClassAndMethodNaming() | |
var headlessTestScene = architecture.GetAttributeOfType(typeof(HeadlessTestAttribute)); | ||
|
||
// get all test classes | ||
var testClasses = architecture.Classes.Where(x => | ||
{ | ||
if (x.Namespace.RelativeNameStartsWith(GetExecuteProject(), "Helper")) | ||
return false; | ||
|
||
return x.Namespace.RelativeNameStartsWith(GetExecuteProject(), ""); | ||
}) | ||
.Except(new[] | ||
{ | ||
architecture.GetClassOfType(typeof(KaraokeTestBrowser)), | ||
architecture.GetClassOfType(typeof(VisualTestRunner)), | ||
}).ToArray(); | ||
var testClasses = architecture.GetAllTestClass().ToArray(); | ||
|
||
Assertion(() => | ||
{ | ||
Assert.NotZero(testClasses.Length, "No test class found"); | ||
|
||
foreach (var testClass in testClasses) | ||
{ | ||
var testMethods = testClass.GetAllTestMembers(architecture).ToArray(); | ||
|
@@ -88,4 +77,25 @@ public void CheckTestClassAndMethodNaming() | |
} | ||
}); | ||
} | ||
|
||
[Test] | ||
[Project.KaraokeTest(true)] | ||
public void CheckAssertion() | ||
{ | ||
var architecture = GetProjectArchitecture(); | ||
var tests = architecture.GetAllTestClass(); | ||
var assert = architecture.GetClassOfType(typeof(Assert)); | ||
|
||
Assertion(() => | ||
{ | ||
foreach (var test in tests) | ||
{ | ||
var assertions = test.GetCalledMethods().Where(x => EqualityComparer<IType>.Default.Equals(x.DeclaringType, assert)).ToArray(); | ||
|
||
// Assertion. | ||
Assert.IsFalse(assertions.Any(x => x.NameStartsWith("True")), $"Should use {nameof(Assert.IsTrue)} instead of {nameof(Assert.True)} in the {test}."); | ||
Assert.IsFalse(assertions.Any(x => x.NameStartsWith("False")), $"Should use {nameof(Assert.IsFalse)} instead of {nameof(Assert.False)} in the {test}."); | ||
} | ||
}); | ||
} | ||
} |
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