From f8719a1f8357d14d248802ddb4a8f302338998f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 22 Jan 2025 21:01:23 +0100 Subject: [PATCH 1/6] Use MSTest runner --- Tests/Tests.csproj | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index b0b5ac4d..83a58d59 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -5,6 +5,10 @@ AsaTests 0.0.0-placeholder net8.0;net9.0 + true + Exe + true + true @@ -13,15 +17,9 @@ - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + From 6f48d4eec08bc346d5438df56aecb626bcceea81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 22 Jan 2025 21:01:36 +0100 Subject: [PATCH 2/6] Enable tests parallelization --- Tests/AsaAnalyzerTests.cs | 11 ----------- Tests/CollectorTests.cs | 7 ------- Tests/ExportTests.cs | 7 ------- Tests/GlobalSetup.cs | 16 ++++++++++++++++ Tests/HydrationTests.cs | 7 ------- Tests/InMemoryComparatorTests.cs | 7 ------- Tests/RuleFileTests.cs | 7 ------- 7 files changed, 16 insertions(+), 46 deletions(-) create mode 100644 Tests/GlobalSetup.cs diff --git a/Tests/AsaAnalyzerTests.cs b/Tests/AsaAnalyzerTests.cs index d76a4f6a..3fe20b1b 100644 --- a/Tests/AsaAnalyzerTests.cs +++ b/Tests/AsaAnalyzerTests.cs @@ -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() { diff --git a/Tests/CollectorTests.cs b/Tests/CollectorTests.cs index 207d12d4..bef59c05 100644 --- a/Tests/CollectorTests.cs +++ b/Tests/CollectorTests.cs @@ -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(); - } - /// /// Does not require admin. /// diff --git a/Tests/ExportTests.cs b/Tests/ExportTests.cs index 2a51e7e1..4edbedb6 100644 --- a/Tests/ExportTests.cs +++ b/Tests/ExportTests.cs @@ -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(); - } - /// /// Does not require admin. /// diff --git a/Tests/GlobalSetup.cs b/Tests/GlobalSetup.cs new file mode 100644 index 00000000..7a116a12 --- /dev/null +++ b/Tests/GlobalSetup.cs @@ -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(); + } +} \ No newline at end of file diff --git a/Tests/HydrationTests.cs b/Tests/HydrationTests.cs index 52838772..bb6acf59 100644 --- a/Tests/HydrationTests.cs +++ b/Tests/HydrationTests.cs @@ -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() { diff --git a/Tests/InMemoryComparatorTests.cs b/Tests/InMemoryComparatorTests.cs index 93abb82d..27b25483 100644 --- a/Tests/InMemoryComparatorTests.cs +++ b/Tests/InMemoryComparatorTests.cs @@ -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() { diff --git a/Tests/RuleFileTests.cs b/Tests/RuleFileTests.cs index 93ea1325..9af53a4e 100644 --- a/Tests/RuleFileTests.cs +++ b/Tests/RuleFileTests.cs @@ -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(); - } - /// /// Verify that embedded rules have no issues /// From 02c07d490ecc96d914d0d4e5146d28e05370e007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 22 Jan 2025 21:06:33 +0100 Subject: [PATCH 3/6] Apply MSTest analyzers feedback --- Tests/HydrationTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/HydrationTests.cs b/Tests/HydrationTests.cs index bb6acf59..ef5ce8aa 100644 --- a/Tests/HydrationTests.cs +++ b/Tests/HydrationTests.cs @@ -49,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] @@ -98,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] From b86bf9de4ebaff86005c483f6dc85dae0057ecbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 22 Jan 2025 21:21:19 +0100 Subject: [PATCH 4/6] Remove test parallelization --- Tests/GlobalSetup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/GlobalSetup.cs b/Tests/GlobalSetup.cs index 7a116a12..7f95488d 100644 --- a/Tests/GlobalSetup.cs +++ b/Tests/GlobalSetup.cs @@ -1,7 +1,7 @@ using Microsoft.CST.AttackSurfaceAnalyzer.Utils; using Microsoft.VisualStudio.TestTools.UnitTesting; -[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] +//[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] [assembly: ClassCleanupExecution(ClassCleanupBehavior.EndOfClass)] [TestClass] From 3713b8eaf275cdc3e01ec4a160168b8ab3b2c182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 23 Jan 2025 08:44:13 +0100 Subject: [PATCH 5/6] Reenabe parallelization --- Tests/GlobalSetup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/GlobalSetup.cs b/Tests/GlobalSetup.cs index 7f95488d..7a116a12 100644 --- a/Tests/GlobalSetup.cs +++ b/Tests/GlobalSetup.cs @@ -1,7 +1,7 @@ using Microsoft.CST.AttackSurfaceAnalyzer.Utils; using Microsoft.VisualStudio.TestTools.UnitTesting; -//[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] +[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] [assembly: ClassCleanupExecution(ClassCleanupBehavior.EndOfClass)] [TestClass] From 016130a4d09fcb0565994012ac3ccd76e41d4bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 3 Feb 2025 11:19:50 +0100 Subject: [PATCH 6/6] Coverage and trx on pipeline --- Pipelines/asa-pr.yml | 3 ++- Pipelines/asa-release.yml | 3 ++- Tests/Tests.csproj | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Pipelines/asa-pr.yml b/Pipelines/asa-pr.yml index b07fdcfc..0ad1158d 100644 --- a/Pipelines/asa-pr.yml +++ b/Pipelines/asa-pr.yml @@ -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 @@ -52,6 +52,7 @@ extends: poolImage: MSSecurity-1ES-Windows-2022 poolOs: windows projectPath: 'Tests/Tests.csproj' + dotnetTestArgs: '-- --coverage --report-trx' - stage: Build dependsOn: Test diff --git a/Pipelines/asa-release.yml b/Pipelines/asa-release.yml index 7d846881..b071b7e1 100644 --- a/Pipelines/asa-release.yml +++ b/Pipelines/asa-release.yml @@ -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 @@ -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: diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 83a58d59..41e6fa8f 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -17,8 +17,8 @@ - - + +