diff --git a/its/src/test/java/com/sonar/it/csharp/AutoGeneratedTest.java b/its/src/test/java/com/sonar/it/csharp/AutoGeneratedTest.java index 4a065721fde..13d87e8149b 100644 --- a/its/src/test/java/com/sonar/it/csharp/AutoGeneratedTest.java +++ b/its/src/test/java/com/sonar/it/csharp/AutoGeneratedTest.java @@ -94,6 +94,6 @@ private BuildResult analyzeCoverageTestProject(String projectName, boolean analy .setParam("value", "" + analyzeGenerated) .execute(); - return Tests.analyzeProject(temp, projectName, null, keyValues); + return Tests.analyzeProject(temp, projectName, keyValues); } } diff --git a/its/src/test/java/com/sonar/it/csharp/CoverageTest.java b/its/src/test/java/com/sonar/it/csharp/CoverageTest.java index aff77054cf8..302415fa685 100644 --- a/its/src/test/java/com/sonar/it/csharp/CoverageTest.java +++ b/its/src/test/java/com/sonar/it/csharp/CoverageTest.java @@ -117,7 +117,7 @@ void open_cover_on_MultipleProjects_with_UnixWildcardPattern() throws Exception @Test void open_cover_with_deterministic_source_paths() throws Exception { - BuildResult buildResult = Tests.analyzeProject(temp, "CoverageWithDeterministicSourcePaths", "no_rule", "sonar.cs.opencover.reportsPaths", "opencover.xml"); + BuildResult buildResult = Tests.analyzeProject(temp, "CoverageWithDeterministicSourcePaths", "sonar.cs.opencover.reportsPaths", "opencover.xml"); assertThat(buildResult.getLogs()).contains( "Sensor C# Tests Coverage Report Import", @@ -169,7 +169,7 @@ void visual_studio_on_MultipleProjects() throws Exception { @Test void visual_studio_with_deterministic_source_paths() throws Exception { - BuildResult buildResult = Tests.analyzeProject(temp, "CoverageWithDeterministicSourcePaths", "no_rule", "sonar.cs.vscoveragexml.reportsPaths", "VisualStudio.coveragexml"); + BuildResult buildResult = Tests.analyzeProject(temp, "CoverageWithDeterministicSourcePaths", "sonar.cs.vscoveragexml.reportsPaths", "VisualStudio.coveragexml"); assertThat(buildResult.getLogs()).contains( "Sensor C# Tests Coverage Report Import", @@ -184,7 +184,7 @@ void visual_studio_with_deterministic_source_paths() throws Exception { @Test void no_coverage_on_tests() throws Exception { - BuildResult buildResult = Tests.analyzeProject(temp, "NoCoverageOnTests", "no_rule", "sonar.cs.vscoveragexml.reportsPaths", "reports/visualstudio.coveragexml"); + BuildResult buildResult = Tests.analyzeProject(temp, "NoCoverageOnTests", "sonar.cs.vscoveragexml.reportsPaths", "reports/visualstudio.coveragexml"); assertThat(buildResult.getLogs()).contains( "Sensor C# Tests Coverage Report Import", @@ -209,15 +209,15 @@ void should_support_wildcard_patterns() throws Exception { } private BuildResult analyzeCoverageTestProject(String... keyValues) throws IOException { - return Tests.analyzeProject(temp, "CoverageTest", "no_rule", keyValues); + return Tests.analyzeProject(temp, "CoverageTest", keyValues); } private BuildResult analyzeMultipleProjectsTestProject(String coverageProperty, String coverageFileName) throws IOException { - return Tests.analyzeProject(temp, "CoverageTest.MultipleProjects", "no_rule", coverageProperty, coverageFileName); + return Tests.analyzeProject(temp, "CoverageTest.MultipleProjects", coverageProperty, coverageFileName); } private BuildResult analyzeMultipleFrameworksTestProject(String coverageProperty, String coverageFileNames) throws IOException { - return Tests.analyzeProject(temp, "CoverageTest.MultipleFrameworks", "no_rule", coverageProperty, coverageFileNames); + return Tests.analyzeProject(temp, "CoverageTest.MultipleFrameworks", coverageProperty, coverageFileNames); } private void assertCoverageMetrics(String componentKey, int linesToCover, int uncoveredLines, int conditionsToCover, int uncoveredConditions) { diff --git a/its/src/test/java/com/sonar/it/csharp/ExternalIssuesTest.java b/its/src/test/java/com/sonar/it/csharp/ExternalIssuesTest.java index 87e3697404e..fbda4ccac2f 100644 --- a/its/src/test/java/com/sonar/it/csharp/ExternalIssuesTest.java +++ b/its/src/test/java/com/sonar/it/csharp/ExternalIssuesTest.java @@ -81,7 +81,7 @@ void external_issues_imported_by_default_for_test_project() throws Exception { void external_issues_are_ignored() throws Exception { var projectKey = MAIN_PROJECT_DIR + "_ignored"; var componentId = projectKey + PROGRAM_COMPONENT_ID; - Tests.analyzeProject(projectKey, temp, MAIN_PROJECT_DIR, null, + Tests.analyzeProject(projectKey, temp, MAIN_PROJECT_DIR, "sonar.cs.roslyn.ignoreIssues", "true"); assertThat(getComponent(componentId)).isNotNull(); @@ -96,7 +96,7 @@ void external_issues_are_ignored() throws Exception { void external_issues_categories_multiple_categories_mapped() throws Exception { var projectKey = MAIN_PROJECT_DIR + "_categories_mapped"; var componentId = projectKey + PROGRAM_COMPONENT_ID; - Tests.analyzeProject(projectKey, temp, MAIN_PROJECT_DIR, null, + Tests.analyzeProject(projectKey, temp, MAIN_PROJECT_DIR, // notice that bugCategories has a list of 2 external categories "sonar.cs.roslyn.bugCategories", "StyleCop.CSharp.DocumentationRules,StyleCop.CSharp.MaintainabilityRules", "sonar.cs.roslyn.vulnerabilityCategories", "StyleCop.CSharp.OrderingRules"); @@ -124,7 +124,7 @@ void external_issues_categories_multiple_categories_mapped() throws Exception { void external_issues_all_three_properties() throws Exception { var projectKey = MAIN_PROJECT_DIR + "_three_properties"; var componentId = projectKey + PROGRAM_COMPONENT_ID; - Tests.analyzeProject(projectKey, temp, MAIN_PROJECT_DIR, null, + Tests.analyzeProject(projectKey, temp, MAIN_PROJECT_DIR, "sonar.cs.roslyn.codeSmellCategories", "StyleCop.CSharp.DocumentationRules", "sonar.cs.roslyn.bugCategories", "StyleCop.CSharp.MaintainabilityRules", "sonar.cs.roslyn.vulnerabilityCategories", "StyleCop.CSharp.OrderingRules"); diff --git a/its/src/test/java/com/sonar/it/csharp/IncrementalAnalysisTest.java b/its/src/test/java/com/sonar/it/csharp/IncrementalAnalysisTest.java index 25a0db9b550..7246de03263 100644 --- a/its/src/test/java/com/sonar/it/csharp/IncrementalAnalysisTest.java +++ b/its/src/test/java/com/sonar/it/csharp/IncrementalAnalysisTest.java @@ -52,7 +52,7 @@ class IncrementalAnalysisTest { @Test void incrementalPrAnalysis_NoCache_FullAnalysisDone() throws IOException { var projectKey = PROJECT_DIR + "_noCache_fullAnalysis"; - Tests.analyzeProject(projectKey, temp, PROJECT_DIR, null, "sonar.branch.name", "base-branch", "sonar.analysisCache.enabled", "false"); + Tests.analyzeProject(projectKey, temp, PROJECT_DIR, "sonar.branch.name", "base-branch", "sonar.analysisCache.enabled", "false"); Path projectDir = TestUtils.projectDir(temp, PROJECT_DIR); File withChangesPath = projectDir.resolve(PROJECT_DIR + "\\WithChanges.cs").toFile(); addIssue(withChangesPath); @@ -73,7 +73,7 @@ void incrementalPrAnalysis_NoCache_FullAnalysisDone() throws IOException { @Test void incrementalPrAnalysis_cacheAvailableNoChanges_nothingReported() throws IOException { var projectKey = PROJECT_DIR + "cacheAvailable_noChanges"; - Tests.analyzeProject(projectKey, temp, PROJECT_DIR, null, "sonar.branch.name", "base-branch"); + Tests.analyzeProject(projectKey, temp, PROJECT_DIR, "sonar.branch.name", "base-branch"); Path projectDir = TestUtils.projectDir(temp, PROJECT_DIR); BeginAndEndStepResults results = executeAnalysisForPRBranch(projectKey, projectDir, ""); @@ -90,7 +90,7 @@ void incrementalPrAnalysis_cacheAvailableNoChanges_nothingReported() throws IOEx @Test void incrementalPrAnalysis_cacheAvailableChangesDone_issuesReportedForChangedFiles() throws IOException { var projectKey = PROJECT_DIR + "cacheAvailable_withChanges"; - Tests.analyzeProject(projectKey, temp, PROJECT_DIR, null, "sonar.branch.name", "base-branch"); + Tests.analyzeProject(projectKey, temp, PROJECT_DIR, "sonar.branch.name", "base-branch"); Path projectDir = TestUtils.projectDir(temp, PROJECT_DIR); File unchanged1Path = projectDir.resolve(PROJECT_DIR + "\\Unchanged1.cs").toFile(); File unchanged2Path = projectDir.resolve(PROJECT_DIR + "\\Unchanged2.cs").toFile(); @@ -124,7 +124,7 @@ void incrementalPrAnalysis_cacheAvailableChangesDone_issuesReportedForChangedFil @Test void incrementalPrAnalysis_cacheAvailableProjectBaseDirChanged_everythingIsReanalyzed() throws IOException { var projectKey = PROJECT_DIR + "cacheAvailable_baseDirChanged"; - Tests.analyzeProject(projectKey, temp, PROJECT_DIR, null, "sonar.branch.name", "base-branch"); + Tests.analyzeProject(projectKey, temp, PROJECT_DIR, "sonar.branch.name", "base-branch"); Path projectDir = TestUtils.projectDir(temp, PROJECT_DIR); File withChangesPath = projectDir.resolve(PROJECT_DIR + "\\WithChanges.cs").toFile(); addIssue(withChangesPath); @@ -153,7 +153,7 @@ void incrementalPrAnalysis_cacheAvailableProjectBaseDirChanged_everythingIsReana @Test void incrementalPrAnalysis_cacheAvailableDuplicationIntroduced_duplicationReportedForChangedFile() throws IOException { String projectKey = "IncrementalPRAnalysisDuplication"; - Tests.analyzeProject(temp, projectKey, null, "sonar.branch.name", "base-branch"); + Tests.analyzeProject(temp, projectKey, "sonar.branch.name", "base-branch"); Path projectDir = TestUtils.projectDir(temp, projectKey); File originalFile = projectDir.resolve("IncrementalPRAnalysisDuplication\\OriginalClass.cs").toFile(); File duplicatedFile = projectDir.resolve("IncrementalPRAnalysisDuplication\\CopyClass.cs").toFile(); diff --git a/its/src/test/java/com/sonar/it/csharp/MetricsIncludeHeaderCommentTest.java b/its/src/test/java/com/sonar/it/csharp/MetricsIncludeHeaderCommentTest.java index d9db0a1e8c0..31bb48ce585 100644 --- a/its/src/test/java/com/sonar/it/csharp/MetricsIncludeHeaderCommentTest.java +++ b/its/src/test/java/com/sonar/it/csharp/MetricsIncludeHeaderCommentTest.java @@ -58,7 +58,6 @@ public class MetricsIncludeHeaderCommentTest { public static void beforeAll() throws Exception { Path projectDir = TestUtils.projectDir(temp, "MetricsTest"); ScannerForMSBuild beginStep = TestUtils.createBeginStep(PROJECT_KEY, projectDir) - .setProfile("no_rule") // Without that, the MetricsTest project is considered as a Test project :) .setProperty("sonar.msbuild.testProjectPattern", "noTests"); diff --git a/its/src/test/java/com/sonar/it/csharp/MetricsTest.java b/its/src/test/java/com/sonar/it/csharp/MetricsTest.java index 2c5487d7fd7..f25321287a4 100644 --- a/its/src/test/java/com/sonar/it/csharp/MetricsTest.java +++ b/its/src/test/java/com/sonar/it/csharp/MetricsTest.java @@ -44,7 +44,7 @@ public class MetricsTest { @BeforeAll public static void beforeAll() throws Exception { // Without setting the testProjectPattern, the MetricsTest project is considered as a Test project :) - Tests.analyzeProject(temp, PROJECT, "no_rule", "sonar.msbuild.testProjectPattern", "noTests"); + Tests.analyzeProject(temp, PROJECT, "sonar.msbuild.testProjectPattern", "noTests"); } @Test diff --git a/its/src/test/java/com/sonar/it/csharp/NoSonarTest.java b/its/src/test/java/com/sonar/it/csharp/NoSonarTest.java index c23850c5165..b3186058e99 100644 --- a/its/src/test/java/com/sonar/it/csharp/NoSonarTest.java +++ b/its/src/test/java/com/sonar/it/csharp/NoSonarTest.java @@ -43,7 +43,7 @@ public class NoSonarTest { @BeforeAll public static void init() throws Exception { - buildResult = Tests.analyzeProject(temp, PROJECT, "class_name"); + buildResult = Tests.analyzeProject(temp, PROJECT); } @Test diff --git a/its/src/test/java/com/sonar/it/csharp/RazorMetricsTest.java b/its/src/test/java/com/sonar/it/csharp/RazorMetricsTest.java index 479ccf24872..f6673bc8143 100644 --- a/its/src/test/java/com/sonar/it/csharp/RazorMetricsTest.java +++ b/its/src/test/java/com/sonar/it/csharp/RazorMetricsTest.java @@ -41,7 +41,7 @@ public class RazorMetricsTest { @BeforeAll public static void beforeAll() throws Exception { - Tests.analyzeProject(temp, PROJECT, "no_rule"); + Tests.analyzeProject(temp, PROJECT); } @Test diff --git a/its/src/test/java/com/sonar/it/csharp/SharedFilesTest.java b/its/src/test/java/com/sonar/it/csharp/SharedFilesTest.java index 5f1642c389b..293babed28a 100644 --- a/its/src/test/java/com/sonar/it/csharp/SharedFilesTest.java +++ b/its/src/test/java/com/sonar/it/csharp/SharedFilesTest.java @@ -40,7 +40,7 @@ class SharedFilesTest { @Test void should_analyze_shared_files() throws Exception { - BuildResult buildResult = Tests.analyzeProject(temp, "SharedFilesTest", null, "sonar.cs.vscoveragexml.reportsPaths", "reports/visualstudio.coveragexml"); + BuildResult buildResult = Tests.analyzeProject(temp, "SharedFilesTest", "sonar.cs.vscoveragexml.reportsPaths", "reports/visualstudio.coveragexml"); assertThat(getComponent("SharedFilesTest:Class1.cs")).isNotNull(); assertThat(getComponent("SharedFilesTest:ConsoleApp1/Program1.cs")).isNotNull(); diff --git a/its/src/test/java/com/sonar/it/csharp/SymbolicLinksTest.java b/its/src/test/java/com/sonar/it/csharp/SymbolicLinksTest.java index 87dc76895e9..db6b92b64c8 100644 --- a/its/src/test/java/com/sonar/it/csharp/SymbolicLinksTest.java +++ b/its/src/test/java/com/sonar/it/csharp/SymbolicLinksTest.java @@ -51,7 +51,7 @@ void should_supportS_symbolic_links() throws Exception { try { Files.createSymbolicLink(link, target); - var buildResult = Tests.analyzeProjectPath("SymbolicLinks", projectFullPath, null, "sonar.verbose", "true"); + var buildResult = Tests.analyzeProjectPath("SymbolicLinks", projectFullPath, "sonar.verbose", "true"); assertThat(buildResult.isSuccess()).isTrue(); diff --git a/its/src/test/java/com/sonar/it/csharp/TestProjectTest.java b/its/src/test/java/com/sonar/it/csharp/TestProjectTest.java index 3a1c1ecdab7..8a4e61c0e65 100644 --- a/its/src/test/java/com/sonar/it/csharp/TestProjectTest.java +++ b/its/src/test/java/com/sonar/it/csharp/TestProjectTest.java @@ -97,7 +97,7 @@ void issuesAreImportedForTestProject() { @Test void with_html_and_csharp_code_explicitly_marked_as_test_should_not_populate_metrics() throws Exception { - BuildResult buildResult = Tests.analyzeProject(temp, EXPLICITLY_MARKED_AS_TEST, "no_rule"); + BuildResult buildResult = Tests.analyzeProject(temp, EXPLICITLY_MARKED_AS_TEST); assertThat(Tests.getComponent("HtmlCSharpExplicitlyMarkedAsTest:Foo.cs")).isNotNull(); assertThat(getMeasureAsInt(EXPLICITLY_MARKED_AS_TEST, "files")).isNull(); diff --git a/its/src/test/java/com/sonar/it/csharp/Tests.java b/its/src/test/java/com/sonar/it/csharp/Tests.java index 838098d1ec0..91348de99ac 100644 --- a/its/src/test/java/com/sonar/it/csharp/Tests.java +++ b/its/src/test/java/com/sonar/it/csharp/Tests.java @@ -71,26 +71,20 @@ public void afterAll(ExtensionContext extensionContext) throws Exception { public static BuildResult analyzeProject(Path temp, String projectDir) throws IOException { return analyzeProject(projectDir, temp, projectDir); } - - public static BuildResult analyzeProject(String projectKey, Path temp, String projectDir) throws IOException { - return analyzeProject(projectKey, temp, projectDir, null); - } - - public static BuildResult analyzeProject(Path temp, String projectDir, @Nullable String profileKey, String... keyValues) throws IOException { - return analyzeProject(projectDir, temp, projectDir, profileKey, keyValues); + + public static BuildResult analyzeProject(Path temp, String projectDir, String... keyValues) throws IOException { + return analyzeProject(projectDir, temp, projectDir, keyValues); } - public static BuildResult analyzeProject(String projectKey, Path temp, String projectDir, @Nullable String profileKey, String... keyValues) throws IOException { + public static BuildResult analyzeProject(String projectKey, Path temp, String projectDir, String... keyValues) throws IOException { Path projectFullPath = TestUtils.projectDir(temp, projectDir); - return analyzeProjectPath(projectKey, projectFullPath, profileKey, keyValues); + return analyzeProjectPath(projectKey, projectFullPath, keyValues); } - public static BuildResult analyzeProjectPath(String projectKey, Path projectFullPath, @Nullable String profileKey, String... keyValues) { + public static BuildResult analyzeProjectPath(String projectKey, Path projectFullPath, String... keyValues) { ScannerForMSBuild beginStep = TestUtils.createBeginStep(projectKey, projectFullPath) - .setProfile(profileKey) .setProperties(keyValues); - ORCHESTRATOR.executeBuild(beginStep); TestUtils.runBuild(projectFullPath); return ORCHESTRATOR.executeBuild(TestUtils.createEndStep(projectFullPath)); diff --git a/its/src/test/java/com/sonar/it/csharp/UnitTestResultsTest.java b/its/src/test/java/com/sonar/it/csharp/UnitTestResultsTest.java index c38a6b11015..7313ba834cb 100644 --- a/its/src/test/java/com/sonar/it/csharp/UnitTestResultsTest.java +++ b/its/src/test/java/com/sonar/it/csharp/UnitTestResultsTest.java @@ -79,6 +79,6 @@ void should_support_wildcard_patterns() throws Exception { } private BuildResult analyzeTestProject(String... keyValues) throws IOException { - return Tests.analyzeProject(temp, PROJECT, "no_rule", keyValues); + return Tests.analyzeProject(temp, PROJECT, keyValues); } } diff --git a/its/src/test/java/com/sonar/it/shared/CoverageTest.java b/its/src/test/java/com/sonar/it/shared/CoverageTest.java index 7d7592b4238..c6c93175e76 100644 --- a/its/src/test/java/com/sonar/it/shared/CoverageTest.java +++ b/its/src/test/java/com/sonar/it/shared/CoverageTest.java @@ -86,6 +86,6 @@ public void mix_only_vbnet_vscoverage() throws IOException { } private BuildResult analyzeCoverageMixProject(String... keyValues) throws IOException { - return Tests.analyzeProject(temp, "CSharpVBNetCoverage", null, keyValues); + return Tests.analyzeProject(temp, "CSharpVBNetCoverage", keyValues); } } diff --git a/its/src/test/java/com/sonar/it/shared/Tests.java b/its/src/test/java/com/sonar/it/shared/Tests.java index 2de0d780679..6cca13f5252 100644 --- a/its/src/test/java/com/sonar/it/shared/Tests.java +++ b/its/src/test/java/com/sonar/it/shared/Tests.java @@ -52,14 +52,9 @@ public void afterAll(ExtensionContext extensionContext) throws Exception { ORCHESTRATOR_STATE.stopOnce(); } - public static BuildResult analyzeProject(Path temp, String projectDir) throws IOException { - return analyzeProject(temp, projectDir, null); - } - - public static BuildResult analyzeProject(Path temp, String projectDir, @Nullable String profileKey, String... keyValues) throws IOException { + public static BuildResult analyzeProject(Path temp, String projectDir, String... keyValues) throws IOException { Path projectFullPath = TestUtils.projectDir(temp, projectDir); ScannerForMSBuild beginStep = TestUtils.createBeginStep(projectDir, projectFullPath) - .setProfile(profileKey) .setProperties(keyValues); ORCHESTRATOR.executeBuild(beginStep); TestUtils.runBuild(projectFullPath); diff --git a/its/src/test/java/com/sonar/it/vbnet/AutoGeneratedTest.java b/its/src/test/java/com/sonar/it/vbnet/AutoGeneratedTest.java index aa014c8e5bd..50d339baa4d 100644 --- a/its/src/test/java/com/sonar/it/vbnet/AutoGeneratedTest.java +++ b/its/src/test/java/com/sonar/it/vbnet/AutoGeneratedTest.java @@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(Tests.class) -public class AutoGeneratedTest { +class AutoGeneratedTest { @TempDir private static Path temp; @@ -40,7 +40,7 @@ public class AutoGeneratedTest { private final String PROJECT_NAME = "VbAutoGeneratedFiles"; @Test - public void autogenerated_code_with_analyzeGenerated_false() throws Exception { + void autogenerated_code_with_analyzeGenerated_false() throws Exception { analyzeCoverageTestProject(PROJECT_NAME, false); // only MyModule.vb is scanned @@ -50,7 +50,7 @@ public void autogenerated_code_with_analyzeGenerated_false() throws Exception { } @Test - public void autogenerated_code_with_analyzeGenerated_true() throws Exception { + void autogenerated_code_with_analyzeGenerated_true() throws Exception { analyzeCoverageTestProject(PROJECT_NAME, true); assertThat(getMeasureAsInt(PROJECT_NAME, "files")).isEqualTo(6); @@ -59,7 +59,7 @@ public void autogenerated_code_with_analyzeGenerated_true() throws Exception { } @Test - public void autogenerated_files_are_logged() throws Exception { + void autogenerated_files_are_logged() throws Exception { BuildResult result = analyzeCoverageTestProject(PROJECT_NAME, false, "sonar.verbose", "true"); assertThat(result.getLogsLines(x -> x.contains("was recognized as generated"))).hasSize(7); @@ -74,9 +74,9 @@ private BuildResult analyzeCoverageTestProject(String projectName, boolean analy .setAdminCredentials() .setMethod(HttpMethod.POST) .setParam("key", "sonar.vbnet.analyzeGeneratedCode") - .setParam("value", "" + analyzeGenerated) + .setParam("value", String.valueOf(analyzeGenerated)) .execute(); - return Tests.analyzeProject(temp, projectName, null, keyValues); + return Tests.analyzeProject(temp, projectName, keyValues); } } diff --git a/its/src/test/java/com/sonar/it/vbnet/CoverageTest.java b/its/src/test/java/com/sonar/it/vbnet/CoverageTest.java index 9d768fc3078..1e51c367a0e 100644 --- a/its/src/test/java/com/sonar/it/vbnet/CoverageTest.java +++ b/its/src/test/java/com/sonar/it/vbnet/CoverageTest.java @@ -25,18 +25,20 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import static com.sonar.it.vbnet.Tests.getMeasureAsInt; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(Tests.class) -public class CoverageTest { +class CoverageTest { @TempDir private static Path temp; @Test - public void without_coverage_report_still_count_lines_to_cover() throws Exception { + void without_coverage_report_still_count_lines_to_cover() throws Exception { BuildResult buildResult = analyzeCoverageTestProject(); assertThat(buildResult.getLogs()) @@ -48,57 +50,23 @@ public void without_coverage_report_still_count_lines_to_cover() throws Exceptio assertThat(getMeasureAsInt("VbCoverageTest", "uncovered_lines")).isEqualTo(4); } - @Test - public void ncover3() throws Exception { - BuildResult buildResult = analyzeCoverageTestProject("sonar.vbnet.ncover3.reportsPaths", "reports/ncover3.nccov"); - - assertThat(buildResult.getLogs()).contains( - "Sensor VB.NET Tests Coverage Report Import", - "Coverage Report Statistics: 1 files, 1 main files, 1 main files with coverage, 0 test files, 0 project excluded files, 0 other language files."); - - assertThat(getMeasureAsInt("VbCoverageTest", "lines_to_cover")).isEqualTo(6); - assertThat(getMeasureAsInt("VbCoverageTest", "uncovered_lines")).isEqualTo(1); - } - - @Test - public void open_cover() throws Exception { - BuildResult buildResult = analyzeCoverageTestProject("sonar.vbnet.opencover.reportsPaths", "reports/opencover.xml"); - - assertThat(buildResult.getLogs()).contains( - "Sensor VB.NET Tests Coverage Report Import", - "Coverage Report Statistics: 1 files, 1 main files, 1 main files with coverage, 0 test files, 0 project excluded files, 0 other language files."); - - assertThat(getMeasureAsInt("VbCoverageTest", "lines_to_cover")).isEqualTo(9); - assertThat(getMeasureAsInt("VbCoverageTest", "uncovered_lines")).isEqualTo(1); - } - - @Test - public void dotcover() throws Exception { - BuildResult buildResult = analyzeCoverageTestProject("sonar.vbnet.dotcover.reportsPaths", "reports/dotcover.html"); - - assertThat(buildResult.getLogs()).contains( - "Sensor VB.NET Tests Coverage Report Import", - "Coverage Report Statistics: 1 files, 1 main files, 1 main files with coverage, 0 test files, 0 project excluded files, 0 other language files."); - - assertThat(getMeasureAsInt("VbCoverageTest", "lines_to_cover")).isEqualTo(5); - assertThat(getMeasureAsInt("VbCoverageTest", "uncovered_lines")).isEqualTo(1); - } - - @Test - public void visual_studio() throws Exception { - BuildResult buildResult = analyzeCoverageTestProject("sonar.vbnet.vscoveragexml.reportsPaths", "reports/visualstudio.coveragexml"); + @ParameterizedTest + @CsvSource(value = {"ncover3:nccov:6:1", "opencover:xml:9:1", "dotcover:html:5:1", "vscoveragexml:visualstudio.coveragexml:5:1"}, delimiter = ':') + void coverage(String testFramework, String format, int linesToCover, int uncoveredLines) throws Exception { + String reportFile = testFramework.equals("vscoveragexml") ? format : testFramework + "." + format; + BuildResult buildResult = analyzeCoverageTestProject("sonar.vbnet." + testFramework + ".reportsPaths", "reports/" + reportFile); assertThat(buildResult.getLogs()).contains( "Sensor VB.NET Tests Coverage Report Import", "Coverage Report Statistics: 1 files, 1 main files, 1 main files with coverage, 0 test files, 0 project excluded files, 0 other language files."); - assertThat(getMeasureAsInt("VbCoverageTest", "lines_to_cover")).isEqualTo(5); - assertThat(getMeasureAsInt("VbCoverageTest", "uncovered_lines")).isEqualTo(1); + assertThat(getMeasureAsInt("VbCoverageTest", "lines_to_cover")).isEqualTo(linesToCover); + assertThat(getMeasureAsInt("VbCoverageTest", "uncovered_lines")).isEqualTo(uncoveredLines); } @Test - public void no_coverage_on_tests() throws Exception { - BuildResult buildResult = Tests.analyzeProject(temp, "VbNoCoverageOnTests", "vbnet_no_rule", "sonar.vbnet.vscoveragexml.reportsPaths", "reports/visualstudio.coveragexml"); + void no_coverage_on_tests() throws Exception { + BuildResult buildResult = Tests.analyzeProject(temp, "VbNoCoverageOnTests", "sonar.vbnet.vscoveragexml.reportsPaths", "reports/visualstudio.coveragexml"); assertThat(buildResult.getLogs()).contains( "Sensor VB.NET Tests Coverage Report Import", @@ -113,7 +81,7 @@ public void no_coverage_on_tests() throws Exception { } @Test - public void should_support_wildcard_patterns() throws Exception { + void should_support_wildcard_patterns() throws Exception { BuildResult buildResult = analyzeCoverageTestProject("sonar.vbnet.ncover3.reportsPaths", "reports/*.nccov"); assertThat(buildResult.getLogs()).contains( @@ -124,6 +92,6 @@ public void should_support_wildcard_patterns() throws Exception { } private BuildResult analyzeCoverageTestProject(String... keyValues) throws IOException { - return Tests.analyzeProject(temp, "VbCoverageTest", "vbnet_no_rule", keyValues); + return Tests.analyzeProject(temp, "VbCoverageTest", keyValues); } } diff --git a/its/src/test/java/com/sonar/it/vbnet/MetricsTest.java b/its/src/test/java/com/sonar/it/vbnet/MetricsTest.java index 9a5957aec7a..a11566209ba 100644 --- a/its/src/test/java/com/sonar/it/vbnet/MetricsTest.java +++ b/its/src/test/java/com/sonar/it/vbnet/MetricsTest.java @@ -44,7 +44,7 @@ public class MetricsTest { @BeforeAll public static void beforeAll() throws Exception { // Without setting the testProjectPattern, the VbMetricsTest project is considered as a Test project :) - Tests.analyzeProject(temp, PROJECT, "vbnet_no_rule", "sonar.msbuild.testProjectPattern", "noTests"); + Tests.analyzeProject(temp, PROJECT, "sonar.msbuild.testProjectPattern", "noTests"); } @Test diff --git a/its/src/test/java/com/sonar/it/vbnet/NoSonarTest.java b/its/src/test/java/com/sonar/it/vbnet/NoSonarTest.java index 2be49470f02..856078132f5 100644 --- a/its/src/test/java/com/sonar/it/vbnet/NoSonarTest.java +++ b/its/src/test/java/com/sonar/it/vbnet/NoSonarTest.java @@ -43,7 +43,7 @@ public class NoSonarTest { @BeforeAll public static void init() throws Exception { - buildResult = Tests.analyzeProject(temp, PROJECT, "vbnet_class_name"); + buildResult = Tests.analyzeProject(temp, PROJECT); } @Test diff --git a/its/src/test/java/com/sonar/it/vbnet/Tests.java b/its/src/test/java/com/sonar/it/vbnet/Tests.java index 7a734a70551..88ff57dca92 100644 --- a/its/src/test/java/com/sonar/it/vbnet/Tests.java +++ b/its/src/test/java/com/sonar/it/vbnet/Tests.java @@ -57,14 +57,9 @@ public void afterAll(ExtensionContext extensionContext) throws Exception { ORCHESTRATOR_STATE.stopOnce(); } - static BuildResult analyzeProject(Path temp, String projectName) throws IOException { - return analyzeProject(temp, projectName, null); - } - - static BuildResult analyzeProject(Path temp, String projectDir, @Nullable String profileKey, String... keyValues) throws IOException { + static BuildResult analyzeProject(Path temp, String projectDir, String... keyValues) throws IOException { Path projectFullPath = TestUtils.projectDir(temp, projectDir); ScannerForMSBuild beginStep = TestUtils.createBeginStep(projectDir, projectFullPath) - .setProfile(profileKey) .setProperties(keyValues); ORCHESTRATOR.executeBuild(beginStep); diff --git a/its/src/test/java/com/sonar/it/vbnet/UnitTestResultsTest.java b/its/src/test/java/com/sonar/it/vbnet/UnitTestResultsTest.java index 17f39f049b5..471aa6def27 100644 --- a/its/src/test/java/com/sonar/it/vbnet/UnitTestResultsTest.java +++ b/its/src/test/java/com/sonar/it/vbnet/UnitTestResultsTest.java @@ -38,7 +38,7 @@ public class UnitTestResultsTest { private static final String PROJECT = "VbUnitTestResultsTest"; @Test - public void should_not_import_unit_test_results_without_report() throws Exception { + void should_not_import_unit_test_results_without_report() throws Exception { analyzeTestProject(); assertThat(getMeasure(PROJECT, "tests")).isNull(); @@ -48,7 +48,7 @@ public void should_not_import_unit_test_results_without_report() throws Exceptio } @Test - public void vstest() throws Exception { + void vstest() throws Exception { analyzeTestProject("sonar.vbnet.vstest.reportsPaths", "reports/vstest.trx"); assertThat(getMeasureAsInt(PROJECT, "tests")).isEqualTo(42); @@ -58,7 +58,7 @@ public void vstest() throws Exception { } @Test - public void nunit() throws Exception { + void nunit() throws Exception { analyzeTestProject("sonar.vbnet.nunit.reportsPaths", "reports/nunit.xml"); assertThat(getMeasureAsInt(PROJECT, "tests")).isEqualTo(200); @@ -68,13 +68,13 @@ public void nunit() throws Exception { } @Test - public void should_support_wildcard_patterns() throws Exception { + void should_support_wildcard_patterns() throws Exception { analyzeTestProject("sonar.vbnet.vstest.reportsPaths", "reports/*.trx"); assertThat(getMeasureAsInt(PROJECT, "tests")).isEqualTo(42); } private void analyzeTestProject(String... keyValues) throws IOException { - Tests.analyzeProject(temp, PROJECT, "vbnet_no_rule", keyValues); + Tests.analyzeProject(temp, PROJECT, keyValues); } }