diff --git a/site/xunit.analyzers/rules/index.md b/site/xunit.analyzers/rules/index.md index d890f75..ea7760e 100644 --- a/site/xunit.analyzers/rules/index.md +++ b/site/xunit.analyzers/rules/index.md @@ -89,6 +89,8 @@ Tag | Meani | [xUnit1067](/xunit.analyzers/rules/xUnit1067) | ::v2::{.label .label-version-True} ::v3::{.label .label-version-True} ::AOT::{.label .label-version-True} | ::E::{.label .label-Error .label-Fixed} | There is no matching MemberData method argument | [xUnit1068](/xunit.analyzers/rules/xUnit1068) | ::v2::{.label .label-version-False} ::v3::{.label .label-version-False} ::AOT::{.label .label-version-True} | ::E::{.label .label-Error .label-Fixed} | MemberData cannot point to an open generic type | [xUnit1069](/xunit.analyzers/rules/xUnit1069) | ::v2::{.label .label-version-False} ::v3::{.label .label-version-True} ::AOT::{.label .label-version-True} | ::W::{.label .label-Warning .label-Fixed} | Test methods with a Timeout should reference TestContext.Current.CancellationToken +| [xUnit1070](/xunit.analyzers/rules/xUnit1070) | ::v2::{.label .label-version-False} ::v3::{.label .label-version-True} ::AOT::{.label .label-version-True} | ::E::{.label .label-Error .label-Fixed} | Cultured test methods cannot have null cultures +| [xUnit1071](/xunit.analyzers/rules/xUnit1071) | ::v2::{.label .label-version-False} ::v3::{.label .label-version-True} ::AOT::{.label .label-version-True} | ::W::{.label .label-Warning .label-Fixed} | Cultured test methods should not have duplicate cultures ## Assertion Analyzers (2xxx) diff --git a/site/xunit.analyzers/rules/xUnit1070.md b/site/xunit.analyzers/rules/xUnit1070.md new file mode 100644 index 0000000..d29d26c --- /dev/null +++ b/site/xunit.analyzers/rules/xUnit1070.md @@ -0,0 +1,49 @@ +--- +analyzer: true +title: xUnit1070 +description: Cultured test methods cannot have null cultures +severity: Error +v2: false +v3: true +aot: true +--- + +## Cause + +A violation of this rule occurs when one of the cultures declared on a cultured test is `null`. + +## Reason for rule + +Cultured test methods run one test for each declared culture, so every culture must be a valid culture name. A `null` culture cannot be turned into a culture, so the test framework fails with an error when it discovers the test. + +## How to fix violations + +To fix a violation of this rule, replace the `null` value with a valid culture name, or remove it. + +## Examples + +### Violates + +```csharp +using Xunit; + +public class xUnit1070 +{ + [CulturedFact(["en-US", null])] + public void FactMethod() + { } +} +``` + +### Does not violate + +```csharp +using Xunit; + +public class xUnit1070 +{ + [CulturedFact(["en-US", "fr-FR"])] + public void FactMethod() + { } +} +``` diff --git a/site/xunit.analyzers/rules/xUnit1071.md b/site/xunit.analyzers/rules/xUnit1071.md new file mode 100644 index 0000000..33c6bda --- /dev/null +++ b/site/xunit.analyzers/rules/xUnit1071.md @@ -0,0 +1,49 @@ +--- +analyzer: true +title: xUnit1071 +description: Cultured test methods should not have duplicate cultures +severity: Warning +v2: false +v3: true +aot: true +--- + +## Cause + +A violation of this rule occurs when the same culture is declared more than once on a cultured test. Culture names are compared case-insensitively, so `"en-US"` and `"en-us"` count as duplicates. + +## Reason for rule + +Cultured test methods run one test for each declared culture. A duplicated culture runs the same test more than once under the same culture, which adds no coverage and produces test cases with the same display name and unique ID. + +## How to fix violations + +To fix a violation of this rule, remove the duplicated culture. + +## Examples + +### Violates + +```csharp +using Xunit; + +public class xUnit1071 +{ + [CulturedFact(["en-US", "fr-FR", "en-US"])] + public void FactMethod() + { } +} +``` + +### Does not violate + +```csharp +using Xunit; + +public class xUnit1071 +{ + [CulturedFact(["en-US", "fr-FR"])] + public void FactMethod() + { } +} +```