Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable more rules on test projects #3832

Merged
merged 3 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions test/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Tests specific configuration
# Applies on top of other .editorconfig files

# C# files
[*.cs]

#### .NET Coding Conventions ####

# CA1825: Avoid zero-length array allocations
dotnet_diagnostic.CA1825.severity = warning

# IDE0060: Remove unused parameter
dotnet_diagnostic.IDE0060.severity = warning

# CA1018: Mark attributes with AttributeUsageAttribute
dotnet_diagnostic.CA1018.severity = warning

#### C# Coding Conventions ####

#### .NET Formatting Rules ####

#### C# Formatting Rules ####

#### .NET Naming styles ####

# CA1710: Identifiers should have correct suffix
dotnet_diagnostic.CA1710.severity = warning

#### C# Naming styles ####
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void RunMultipleTestAssemblies(RunnerInfo runnerInfo)

[TestMethod]
[TestCategory("Windows-Review")]
[TestPlatformCompatibilityDataSource()]
[TestPlatformCompatibilityDataSource]
public void RunTestsFromMultipleMSTestAssemblies(RunnerInfo runnerInfo)
{
SetTestEnvironment(_testEnvironment, runnerInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private void AddInProcess(List<RunnerInfo> dataRows)
{
foreach (var adapterVersion in _adapterVersions)
{
AddRow(dataRows, "In process", runnerVersion, runnerFramework, runnerVersion, runnerFramework, adapter, adapterVersion, inIsolation: false);
AddRow(dataRows, "In process", runnerVersion, runnerFramework, runnerVersion, runnerFramework, adapterVersion, inIsolation: false);
}
}
}
Expand All @@ -200,10 +200,10 @@ private void AddOlderConfigurations(List<RunnerInfo> dataRows)
{
var isNetFramework = hostFramework.StartsWith("net4");
var hostVersion = runnerVersion;
foreach (var adapter in _adapters)
foreach (var _ in _adapters)
{
var adapterVersion = _adapterVersions[0];
AddRow(dataRows, "Older", runnerVersion, runnerFramework, hostVersion, hostFramework, adapter, adapterVersion, inIsolation: true);
AddRow(dataRows, "Older", runnerVersion, runnerFramework, hostVersion, hostFramework, adapterVersion, inIsolation: true);
}
}
}
Expand All @@ -225,7 +225,7 @@ private void AddEveryVersionOfAdapter(List<RunnerInfo> dataRows)
{
foreach (var adapterVersion in _adapterVersions)
{
AddRow(dataRows, "Every adapter", runnerVersion, runnerFramework, hostVersion, hostFramework, adapter, adapterVersion, inIsolation: true);
AddRow(dataRows, "Every adapter", runnerVersion, runnerFramework, hostVersion, hostFramework, adapterVersion, inIsolation: true);
}
}
}
Expand All @@ -247,11 +247,11 @@ private void AddEveryVersionOfHost(List<RunnerInfo> dataRows)
var hostVersions = isNetFramework ? Array.Empty<string>() : _hostVersions.ToArray();
foreach (var hostVersion in hostVersions)
{
foreach (var adapter in _adapters)
foreach (var _ in _adapters)
{
// use the newest
var adapterVersion = _adapterVersions[0];
AddRow(dataRows, "Every host", runnerVersion, runnerFramework, hostVersion, hostFramework, adapter, adapterVersion, inIsolation: true);
AddRow(dataRows, "Every host", runnerVersion, runnerFramework, hostVersion, hostFramework, adapterVersion, inIsolation: true);
}
}
}
Expand All @@ -270,19 +270,19 @@ private void AddEveryVersionOfRunner(List<RunnerInfo> dataRows)
// .NET Framework testhost ships with the runner, and the version from the
// runner directory is always selected, otherwise select the newest version from _hostFrameworks.
var hostVersion = isNetFramework ? runnerVersion : _hostVersions[0];
foreach (var adapter in _adapters)
foreach (var _ in _adapters)
{
// use the newest
var adapterVersion = _adapterVersions[0];
AddRow(dataRows, "Every runner", runnerVersion, runnerFramework, hostVersion, hostFramework, adapter, adapterVersion, inIsolation: true);
AddRow(dataRows, "Every runner", runnerVersion, runnerFramework, hostVersion, hostFramework, adapterVersion, inIsolation: true);
}
}
}
}
}

private void AddRow(List<RunnerInfo> dataRows, string batch,
string runnerVersion, string runnerFramework, string hostVersion, string hostFramework, string adapter, string adapterVersion, bool inIsolation)
string runnerVersion, string runnerFramework, string hostVersion, string hostFramework, string adapterVersion, bool inIsolation)
{
RunnerInfo runnerInfo = GetRunnerInfo(batch, runnerFramework, hostFramework, inIsolation);
runnerInfo.DebugInfo = GetDebugInfo();
Expand Down Expand Up @@ -347,7 +347,7 @@ private static VSTestConsoleInfo GetVSTestConsoleInfo(string vstestConsoleVersio
var depsXml = GetDependenciesXml();

// When version is Latest, we built it locally, but it gets restored into our nuget cache on build
// same as other versions, we just need to grab the version from a different property.
// same as other versions, we just need to grab the version from a different property.

var propertyName = vstestConsoleVersion == AcceptanceTestBase.LATEST
? "NETTestSdkVersion"
Expand Down Expand Up @@ -386,7 +386,7 @@ private static NetTestSdkInfo GetNetTestSdkInfo(string testhostVersionType)
var depsXml = GetDependenciesXml();

// When version is Latest, we built it locally, but it gets restored into our nuget cache on build
// same as other versions, we just need to grab the version from a different property.
// same as other versions, we just need to grab the version from a different property.

var propertyName = testhostVersionType == AcceptanceTestBase.LATEST
? "NETTestSdkVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Microsoft.TestPlatform.AcceptanceTests;

public class MSTestCompatibilityDataSource : TestDataSource<RunnerInfo>
public class MSTestCompatibilityDataSource : TestDataSourceAttribute<RunnerInfo>
{
private readonly CompatibilityRowsBuilder _builder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ namespace Microsoft.TestPlatform.AcceptanceTests;
/// AcceptanceTestBase.NETFX452_NET50 = "net452;net472;net48;netcoreapp2.1;netcoreapp3.1;net5.0" to determine which target framework of the project
/// to test. The target project must list those TFMs in the TargetFrameworks property in csproj.
/// </summary>
public class NetCoreRunner : Attribute, ITestDataSource
[AttributeUsage(AttributeTargets.Method)]
public class NetCoreRunnerAttribute : Attribute, ITestDataSource
{
private readonly string _targetFrameworks;

/// <summary>
/// Initializes a new instance of the <see cref="NetCoreTargetFrameworkDataSource"/> class.
/// </summary>
/// <param name="targetFrameworks">To run tests with desktop runner(vstest.console.exe), use AcceptanceTestBase.Net452TargetFramework or alike values.</param>
public NetCoreRunner(string targetFrameworks = AcceptanceTestBase.NETFX452_NET50)
public NetCoreRunnerAttribute(string targetFrameworks = AcceptanceTestBase.NETFX452_NET50)
{
_targetFrameworks = targetFrameworks;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ namespace Microsoft.TestPlatform.AcceptanceTests;
/// If runner framework is net46 then vstest.console.exe will run the tests.
/// Second argument (target framework) = The framework for which test will run
/// </summary>
public class NetCoreTargetFrameworkDataSource : Attribute, ITestDataSource
[AttributeUsage(AttributeTargets.Method)]
public class NetCoreTargetFrameworkDataSourceAttribute : Attribute, ITestDataSource
{
private readonly bool _useDesktopRunner;
private readonly bool _useCoreRunner;
private readonly bool _useNetCore21Target;
private readonly bool _useNetCore31Target;

/// <summary>
/// Initializes a new instance of the <see cref="NetCoreTargetFrameworkDataSource"/> class.
/// Initializes a new instance of the <see cref="NetCoreTargetFrameworkDataSourceAttribute"/> class.
/// </summary>
/// <param name="useDesktopRunner">To run tests with desktop runner(vstest.console.exe)</param>
/// <param name="useCoreRunner">To run tests with core runner(dotnet vstest.console.dll)</param>
public NetCoreTargetFrameworkDataSource(
public NetCoreTargetFrameworkDataSourceAttribute(
bool useDesktopRunner = true,
// adding another runner is not necessary until we need to start building against another
// sdk, because the netcoreapp2.1 executable is forward compatible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ namespace Microsoft.TestPlatform.AcceptanceTests;
/// AcceptanceTestBase.NETFX452_NET50 = "net452;net472;net48;netcoreapp2.1;netcoreapp3.1;net5.0" to determine which target framework of the project
/// to test. The target project must list those TFMs in the TargetFrameworks property in csproj.
/// </summary>
public class NetFrameworkRunner : Attribute, ITestDataSource
[AttributeUsage(AttributeTargets.Method)]
public class NetFrameworkRunnerAttribute : Attribute, ITestDataSource
{
/// <summary>
/// Initializes a new instance of the <see cref="NetCoreTargetFrameworkDataSource"/> class.
/// Initializes a new instance of the <see cref="NetCoreTargetFrameworkDataSourceAttribute"/> class.
/// </summary>
/// <param name="targetFrameworks">To run tests with desktop runner(vstest.console.exe), use AcceptanceTestBase.Net452TargetFramework or alike values.</param>
public NetFrameworkRunner(string targetFrameworks = AcceptanceTestBase.NETFX452_NET50)
public NetFrameworkRunnerAttribute(string targetFrameworks = AcceptanceTestBase.NETFX452_NET50)
{
_targetFrameworks = targetFrameworks;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ namespace Microsoft.TestPlatform.AcceptanceTests;
/// If runner framework is net46 then vstest.console.exe will run the tests.
/// Second argument (target framework) = The framework for which test will run
/// </summary>
public class NetFullTargetFrameworkDataSource : Attribute, ITestDataSource
[AttributeUsage(AttributeTargets.Method)]
public class NetFullTargetFrameworkDataSourceAttribute : Attribute, ITestDataSource
{
private readonly bool _inIsolation;
private readonly bool _inProcess;
private readonly bool _useDesktopRunner;
private readonly bool _useCoreRunner;

/// <summary>
/// Initializes a new instance of the <see cref="NetFullTargetFrameworkDataSource"/> class.
/// Initializes a new instance of the <see cref="NetFullTargetFrameworkDataSourceAttribute"/> class.
/// </summary>
/// <param name="inIsolation">Run test in isolation</param>
/// <param name="inProcess">Run tests in process</param>
/// <param name="useDesktopRunner">To run tests with desktop runner(vstest.console.exe)</param>
/// <param name="useCoreRunner">To run tests with core runner(dotnet vstest.console.dll)</param>
public NetFullTargetFrameworkDataSource(bool inIsolation = true, bool inProcess = false, bool useDesktopRunner = true, bool useCoreRunner = true)
public NetFullTargetFrameworkDataSourceAttribute(bool inIsolation = true, bool inProcess = false, bool useDesktopRunner = true, bool useCoreRunner = true)
{
_inIsolation = inIsolation;
_inProcess = inProcess;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.TestPlatform.AcceptanceTests;
///
/// When that adds up to no configuration exception is thrown.
/// </summary>
public class RunnerCompatibilityDataSource : TestDataSource<RunnerInfo>
public class RunnerCompatibilityDataSource : TestDataSourceAttribute<RunnerInfo>
{
private readonly CompatibilityRowsBuilder _builder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Microsoft.TestPlatform.AcceptanceTests;

[AttributeUsage(AttributeTargets.Method)]
public abstract class TestDataSource<T1> : Attribute, ITestDataSource where T1 : notnull
public abstract class TestDataSourceAttribute<T1> : Attribute, ITestDataSource where T1 : notnull
{
private readonly List<object[]> _data = new();

Expand Down Expand Up @@ -39,7 +39,7 @@ string ITestDataSource.GetDisplayName(MethodInfo methodInfo, object[] data)
}

[AttributeUsage(AttributeTargets.Method)]
public abstract class TestDataSource<T1, T2> : Attribute, ITestDataSource
public abstract class TestDataSourceAttribute<T1, T2> : Attribute, ITestDataSource
where T1 : notnull
where T2 : notnull
{
Expand Down Expand Up @@ -70,7 +70,7 @@ string ITestDataSource.GetDisplayName(MethodInfo methodInfo, object[] data)
}

[AttributeUsage(AttributeTargets.Method)]
public abstract class TestDataSource<T1, T2, T3> : Attribute, ITestDataSource
public abstract class TestDataSourceAttribute<T1, T2, T3> : Attribute, ITestDataSource
where T1 : notnull
where T2 : notnull
where T3 : notnull
Expand Down Expand Up @@ -102,7 +102,7 @@ string ITestDataSource.GetDisplayName(MethodInfo methodInfo, object[] data)
}

[AttributeUsage(AttributeTargets.Method)]
public abstract class TestDataSource<T1, T2, T3, T4> : Attribute, ITestDataSource
public abstract class TestDataSourceAttribute<T1, T2, T3, T4> : Attribute, ITestDataSource
where T1 : notnull
where T2 : notnull
where T3 : notnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Microsoft.TestPlatform.AcceptanceTests;
///
/// When that adds up to no configuration exception is thrown.
/// </summary>
public class TestPlatformCompatibilityDataSource : TestDataSource<RunnerInfo>
public class TestPlatformCompatibilityDataSource : TestDataSourceAttribute<RunnerInfo>
{
private readonly CompatibilityRowsBuilder _builder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.TestPlatform.AcceptanceTests;
///
/// When that adds up to no configuration exception is thrown.
/// </summary>
public class TestHostCompatibilityDataSource : TestDataSource<RunnerInfo>
public class TestHostCompatibilityDataSource : TestDataSourceAttribute<RunnerInfo>
{
private readonly CompatibilityRowsBuilder _builder;

Expand Down
18 changes: 9 additions & 9 deletions test/Microsoft.TestPlatform.AcceptanceTests/RunsettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public void RunSettingsWithParallelAndPlatformX64(RunnerInfo runnerInfo)
}

[TestMethod]
[NetFullTargetFrameworkDataSource(inIsolation: true, inProcess: true)]
[NetFullTargetFrameworkDataSourceAttribute(inIsolation: true, inProcess: true)]
[NetCoreTargetFrameworkDataSource]
public void RunSettingsWithInvalidValueShouldLogError(RunnerInfo runnerInfo)
{
Expand All @@ -259,7 +259,7 @@ public void RunSettingsWithInvalidValueShouldLogError(RunnerInfo runnerInfo)
}

[TestMethod]
[NetFullTargetFrameworkDataSource(inIsolation: true, inProcess: true)]
[NetFullTargetFrameworkDataSourceAttribute(inIsolation: true, inProcess: true)]
[NetCoreTargetFrameworkDataSource]
public void TestAdapterPathFromRunSettings(RunnerInfo runnerInfo)
{
Expand All @@ -283,7 +283,7 @@ public void TestAdapterPathFromRunSettings(RunnerInfo runnerInfo)

[TestMethod]
[TestCategory("Windows-Review")]
[NetFullTargetFrameworkDataSource(inIsolation: true, useCoreRunner: false)]
[NetFullTargetFrameworkDataSourceAttribute(inIsolation: true, useCoreRunner: false)]
public void LegacySettingsWithPlatform(RunnerInfo runnerInfo)
{
SetTestEnvironment(_testEnvironment, runnerInfo);
Expand Down Expand Up @@ -314,7 +314,7 @@ public void LegacySettingsWithPlatform(RunnerInfo runnerInfo)

[TestMethod]
[TestCategory("Windows-Review")]
[NetFullTargetFrameworkDataSource(inIsolation: true, useCoreRunner: false)]
[NetFullTargetFrameworkDataSourceAttribute(inIsolation: true, useCoreRunner: false)]
public void LegacySettingsWithScripts(RunnerInfo runnerInfo)
{
SetTestEnvironment(_testEnvironment, runnerInfo);
Expand Down Expand Up @@ -360,7 +360,7 @@ public void LegacySettingsWithScripts(RunnerInfo runnerInfo)

[TestMethod]
[TestCategory("Windows-Review")]
[NetFullTargetFrameworkDataSource(inIsolation: true, useCoreRunner: false)]
[NetFullTargetFrameworkDataSourceAttribute(inIsolation: true, useCoreRunner: false)]
public void LegacySettingsWithDeploymentItem(RunnerInfo runnerInfo)
{
SetTestEnvironment(_testEnvironment, runnerInfo);
Expand Down Expand Up @@ -397,7 +397,7 @@ public void LegacySettingsWithDeploymentItem(RunnerInfo runnerInfo)

[TestMethod]
[TestCategory("Windows")]
[NetFullTargetFrameworkDataSource(inIsolation: true, useCoreRunner: false)]
[NetFullTargetFrameworkDataSourceAttribute(inIsolation: true, useCoreRunner: false)]
public void LegacySettingsTestTimeout(RunnerInfo runnerInfo)
{
SetTestEnvironment(_testEnvironment, runnerInfo);
Expand All @@ -424,7 +424,7 @@ public void LegacySettingsTestTimeout(RunnerInfo runnerInfo)

[TestMethod]
[TestCategory("Windows-Review")]
[NetFullTargetFrameworkDataSource(inIsolation: true, useCoreRunner: false)]
[NetFullTargetFrameworkDataSourceAttribute(inIsolation: true, useCoreRunner: false)]
public void LegacySettingsAssemblyResolution(RunnerInfo runnerInfo)
{
SetTestEnvironment(_testEnvironment, runnerInfo);
Expand Down Expand Up @@ -505,8 +505,8 @@ public void EnvironmentVariablesSettingsShouldSetEnvironmentVariables(RunnerInfo
[TestMethod]
// patched dotnet is not published on non-windows systems
[TestCategory("Windows-Review")]
[NetFullTargetFrameworkDataSource(useDesktopRunner: false)]
[NetCoreTargetFrameworkDataSource(useDesktopRunner: false)]
[NetFullTargetFrameworkDataSourceAttribute(useDesktopRunner: false)]
[NetCoreTargetFrameworkDataSourceAttribute(useDesktopRunner: false)]
public void RunSettingsAreLoadedFromProject(RunnerInfo runnerInfo)
{
SetTestEnvironment(_testEnvironment, runnerInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class SelfContainedAppTests : AcceptanceTestBase
[TestCategory("Windows-Review")]
// this is core 3.1 only, full framework and netcoreapp2.1 don't "publish" automatically during build
// but if you run it on 2.1 it will pass because we execute the test normally
[NetCoreTargetFrameworkDataSource(useDesktopRunner: false, useNetCore21Target: false, useNetCore31Target: true)]
[NetCoreTargetFrameworkDataSourceAttribute(useDesktopRunner: false, useNetCore21Target: false, useNetCore31Target: true)]
public void RunningApplicationThatIsBuiltAsSelfContainedWillNotFailToFindHostpolicyDll(RunnerInfo runnerInfo)
{
// when the application is self-contained which is dictated by the RuntimeIdentifier and OutputType project
Expand Down
4 changes: 2 additions & 2 deletions test/Microsoft.TestPlatform.AcceptanceTests/TelemetryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TelemetryTests : AcceptanceTestBase
private const string LOG_TELEMETRY_PATH = "VSTEST_LOGTELEMETRY_PATH";

[TestMethod]
[NetFullTargetFrameworkDataSource(inIsolation: true, inProcess: true)]
[NetFullTargetFrameworkDataSourceAttribute(inIsolation: true, inProcess: true)]
[NetCoreTargetFrameworkDataSource]
public void RunTestsShouldPublishMetrics(RunnerInfo runnerInfo)
{
Expand All @@ -30,7 +30,7 @@ public void RunTestsShouldPublishMetrics(RunnerInfo runnerInfo)
}

[TestMethod]
[NetFullTargetFrameworkDataSource(inIsolation: true, inProcess: true)]
[NetFullTargetFrameworkDataSourceAttribute(inIsolation: true, inProcess: true)]
[NetCoreTargetFrameworkDataSource]
public void DiscoverTestsShouldPublishMetrics(RunnerInfo runnerInfo)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.TestPlatform.AcceptanceTests;
public class TestCaseFilterTests : AcceptanceTestBase
{
[TestMethod]
[NetFullTargetFrameworkDataSource(inIsolation: true, inProcess: true)]
[NetFullTargetFrameworkDataSourceAttribute(inIsolation: true, inProcess: true)]
[NetCoreTargetFrameworkDataSource]
public void RunSelectedTestsWithAndOperatorTrait(RunnerInfo runnerInfo)
{
Expand Down
Loading