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

Use MSTest runner + parallelize tests #730

Open
wants to merge 6 commits into
base: release/v2.3
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion Pipelines/asa-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ resources:
- repository: templates
type: git
name: SecurityEngineering/OSS-Tools-Pipeline-Templates
ref: refs/tags/v2.0.0
ref: refs/tags/v2.0.1
- repository: 1esPipelines
type: git
name: 1ESPipelineTemplates/1ESPipelineTemplates
Expand Down Expand Up @@ -52,6 +52,7 @@ extends:
poolImage: MSSecurity-1ES-Windows-2022
poolOs: windows
projectPath: 'Tests/Tests.csproj'
dotnetTestArgs: '-- --coverage --report-trx'

- stage: Build
dependsOn: Test
Expand Down
3 changes: 2 additions & 1 deletion Pipelines/asa-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resources:
- repository: templates
type: git
name: Data/OSS-Tools-Pipeline-Templates
ref: refs/tags/v2.0.0
ref: refs/tags/v2.0.1
- repository: 1esPipelines
type: git
name: 1ESPipelineTemplates/1ESPipelineTemplates
Expand Down Expand Up @@ -42,6 +42,7 @@ extends:
poolImage: MSSecurity-1ES-Windows-2022
poolOs: windows
projectPath: 'Tests/Tests.csproj'
dotnetTestArgs: '-- --coverage --report-trx'
- stage: Build
dependsOn: Test
jobs:
Expand Down
11 changes: 0 additions & 11 deletions Tests/AsaAnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ namespace Microsoft.CST.AttackSurfaceAnalyzer.Tests
[TestClass]
public class AsaAnalyzerTests
{
public AsaAnalyzerTests()
{
}

[ClassInitialize]
public static void ClassSetup(TestContext _)
{
Logger.Setup(false, true);
Strings.Setup();
}

[TestMethod]
public void VerifyEmbeddedRulesAreValid()
{
Expand Down
7 changes: 0 additions & 7 deletions Tests/CollectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ namespace Microsoft.CST.AttackSurfaceAnalyzer.Tests
[TestClass]
public class CollectorTests
{
[ClassInitialize]
public static void ClassSetup(TestContext _)
{
Logger.Setup(false, true);
Strings.Setup();
}

/// <summary>
/// Does not require admin.
/// </summary>
Expand Down
7 changes: 0 additions & 7 deletions Tests/ExportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ namespace Microsoft.CST.AttackSurfaceAnalyzer.Tests
[TestClass]
public class ExportTests
{
[ClassInitialize]
public static void ClassSetup(TestContext _)
{
Logger.Setup(false, true);
Strings.Setup();
}

/// <summary>
/// Does not require admin.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions Tests/GlobalSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.CST.AttackSurfaceAnalyzer.Utils;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)]
[assembly: ClassCleanupExecution(ClassCleanupBehavior.EndOfClass)]

[TestClass]
public static class GlobalSetup
{
[AssemblyInitialize]
public static void AssemblySetup(TestContext _)
{
Logger.Setup(false, true);
Strings.Setup();
}
}
13 changes: 3 additions & 10 deletions Tests/HydrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ namespace Microsoft.CST.AttackSurfaceAnalyzer.Tests
[TestClass]
public class HydrationTests
{
[ClassInitialize]
public static void ClassSetup(TestContext _)
{
Logger.Setup(false, true);
Strings.Setup();
}

[TestMethod]
public void TestSerializeAndDeserializeCertificateObject()
{
Expand Down Expand Up @@ -56,8 +49,8 @@ public void TestSerializeAndDeserializeDriverObject()
var driverObject = new DriverObject(DriverName);
var serialized = JsonUtils.Dehydrate(driverObject);
var rehydrated = JsonUtils.Hydrate(serialized, RESULT_TYPE.DRIVER);
Assert.IsTrue(serialized == JsonUtils.Dehydrate(rehydrated));
Assert.IsTrue(rehydrated.Identity == DriverName);
Assert.AreEqual(JsonUtils.Dehydrate(rehydrated), serialized);
Assert.AreEqual(DriverName, rehydrated.Identity);
}

[TestMethod]
Expand Down Expand Up @@ -105,7 +98,7 @@ public void TestSerializeAndDeserializeProcessObject()
{
var po = ProcessObject.FromProcess(Process.GetCurrentProcess());
var serialized = JsonUtils.Dehydrate(po);
Assert.IsTrue(serialized == JsonUtils.Dehydrate(JsonUtils.Hydrate(serialized, RESULT_TYPE.PROCESS)));
Assert.AreEqual(JsonUtils.Dehydrate(JsonUtils.Hydrate(serialized, RESULT_TYPE.PROCESS)), serialized);
}

[TestMethod]
Expand Down
7 changes: 0 additions & 7 deletions Tests/InMemoryComparatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ namespace Microsoft.CST.AttackSurfaceAnalyzer.Tests
[TestClass]
public class InMemoryComparatorTests
{
[ClassInitialize]
public static void ClassSetup(TestContext _)
{
Logger.Setup(false, true);
Strings.Setup();
}

[TestMethod]
public void TestAddedInMemory()
{
Expand Down
7 changes: 0 additions & 7 deletions Tests/RuleFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ namespace Microsoft.CST.AttackSurfaceAnalyzer.Tests
[TestClass]
public class RuleFileTests
{
[ClassInitialize]
public static void ClassSetup(TestContext _)
{
Logger.Setup(false, true);
Strings.Setup();
}

/// <summary>
/// Verify that embedded rules have no issues
/// </summary>
Expand Down
16 changes: 7 additions & 9 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<AssemblyName>AsaTests</AssemblyName>
<ReleaseVersion>0.0.0-placeholder</ReleaseVersion>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<EnableMSTestRunner>true</EnableMSTestRunner>
<OutputType>Exe</OutputType>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
</PropertyGroup>

<ItemGroup>
Expand All @@ -13,15 +17,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.7.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.7.1" />
<PackageReference Update="MSTest.Analyzers" Version="3.7.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Update="Microsoft.Testing.Extensions.TrxReport" Version="1.5.1" />
<PackageReference Update="Microsoft.Testing.Extensions.CodeCoverage" Version="17.13.1" />
<PackageReference Include="MSTest" Version="3.7.3" />
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="1.5.3" />
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.13.1" />
</ItemGroup>

<ItemGroup>
Expand Down