2929import java .util .HashMap ;
3030import java .util .Map ;
3131import java .util .Set ;
32- import org .junit .Before ;
3332import org .junit .ClassRule ;
3433import org .junit .Test ;
3534
3837
3938public class TestReportTest {
4039
41- private static final String PROJECT = "nosetests_project" ;
4240 public static final String TESTS = "tests" ;
4341 public static final String TEST_FAILURES = "test_failures" ;
4442 public static final String TEST_ERRORS = "test_errors" ;
@@ -49,22 +47,20 @@ public class TestReportTest {
4947 @ ClassRule
5048 public static final Orchestrator ORCHESTRATOR = Tests .ORCHESTRATOR ;
5149
52- @ Before
53- public void before () {
54- ORCHESTRATOR .resetData ();
55- }
56-
57- private static SonarScanner createBuild (String testReportPath ) {
50+ private static SonarScanner createBuild (String projectKey , String testReportPath ) {
5851 return SonarScanner .create ()
52+ .setProjectKey (projectKey )
53+ .setProjectName (projectKey )
5954 .setProjectDir (new File ("projects/nosetests_project" ))
6055 .setProperty ("sonar.python.xunit.reportPath" , testReportPath );
6156 }
6257
6358 @ Test
6459 public void import_report () {
60+ final String projectKey = "nosetests_project" ;
6561 // sonar.python.xunit.skipDetails=false by default
66- ORCHESTRATOR .executeBuild (createBuild ("nosetests.xml" ));
67- assertProjectMeasures (PROJECT , new ImmutableMap .Builder <String , Integer >()
62+ ORCHESTRATOR .executeBuild (createBuild (projectKey , "nosetests.xml" ));
63+ assertProjectMeasures (projectKey , new ImmutableMap .Builder <String , Integer >()
6864 .put (TESTS , 3 )
6965 .put (TEST_FAILURES , 1 )
7066 .put (TEST_ERRORS , 1 )
@@ -76,8 +72,9 @@ public void import_report() {
7672
7773 @ Test
7874 public void import_pytest_report () {
79- ORCHESTRATOR .executeBuild (createBuild ("pytest.xml" ));
80- assertProjectMeasures (PROJECT , new ImmutableMap .Builder <String , Integer >()
75+ final String projectKey = "pytest" ;
76+ ORCHESTRATOR .executeBuild (createBuild (projectKey , "pytest.xml" ));
77+ assertProjectMeasures (projectKey , new ImmutableMap .Builder <String , Integer >()
8178 .put (TESTS , 3 )
8279 .put (TEST_FAILURES , 2 )
8380 .put (TEST_ERRORS , 0 )
@@ -89,7 +86,8 @@ public void import_pytest_report() {
8986
9087 @ Test
9188 public void simple_mode () {
92- ORCHESTRATOR .executeBuild (createBuild ("nosetests.xml" ).setProperty ("sonar.python.xunit.skipDetails" , "true" ));
89+ final String projectKey = "nosetests_simple" ;
90+ ORCHESTRATOR .executeBuild (createBuild (projectKey , "nosetests.xml" ).setProperty ("sonar.python.xunit.skipDetails" , "true" ));
9391 Map <String , Integer > values = new HashMap <>();
9492 values .put (TESTS , 3 );
9593 values .put (TEST_FAILURES , 1 );
@@ -98,24 +96,27 @@ public void simple_mode() {
9896 values .put (TEST_EXECUTION_TIME , 1 );
9997 values .put (TEST_SUCCESS_DENSITY , null );
10098
101- assertProjectMeasures (PROJECT , values );
99+ assertProjectMeasures (projectKey , values );
102100 }
103101
104102 @ Test
105103 public void missing_test_report () {
106- ORCHESTRATOR .executeBuild (createBuild ("missing.xml" ));
107- assertProjectMeasures (PROJECT , nullMeasures ());
104+ final String projectKey = "nosetests_missing" ;
105+ ORCHESTRATOR .executeBuild (createBuild (projectKey , "missing.xml" ));
106+ assertProjectMeasures (projectKey , nullMeasures ());
108107 }
109108
110109 @ Test
111110 public void missing_test_report_with_simple_mode () {
112- ORCHESTRATOR .executeBuild (createBuild ("missing.xml" ).setProperty ("sonar.python.xunit.skipDetails" , "true" ));
113- assertProjectMeasures (PROJECT , nullMeasures ());
111+ final String projectKey = "nosetests_missing_simple" ;
112+ ORCHESTRATOR .executeBuild (createBuild (projectKey , "missing.xml" ).setProperty ("sonar.python.xunit.skipDetails" , "true" ));
113+ assertProjectMeasures (projectKey , nullMeasures ());
114114 }
115115
116116 @ Test
117117 public void invalid_test_report () {
118- BuildResult result = ORCHESTRATOR .executeBuildQuietly (createBuild ("invalid_report.xml" ));
118+ final String projectKey = "nosetests_invalid" ;
119+ BuildResult result = ORCHESTRATOR .executeBuildQuietly (createBuild (projectKey , "invalid_report.xml" ));
119120 assertThat (result .isSuccess ()).isTrue ();
120121 assertThat (result .getLogs ()).contains ("Cannot read report 'invalid_report.xml', the following exception occurred:" +
121122 " Unexpected character 't' (code 116) in prolog; expected '<'\n " +
0 commit comments