this lab use unit tests are using Junit. The result of the unit test is published in xml, and the developer should be able to use this to know which unit test his code did not pass.
Go to the Codebuild console : https://console.aws.amazon.com/codebuild
Select Report groups in the right Build tab. Select Create report group at the top right.
Concurrency-Unittest-Report in Report group name of Rport group configuration. Select Test for the report type. Uncheck the box for Export to Amazon S3.
To copy the ARN of the report groups, Concurrency-Unittest-Report from Report groups. The results of the Unittest here will now be shown. Copy the contents of Report group ARN of Configuration.
Now let’s go back to Cloud9 and edit buildspec.yml. buildspec.yml is located in ConcurrencySample’s root directory.
Double-click the file to add content. Paste the Report group ARN to
reports: <YOUR-REPORT-GROUP-ARN>: files: - '**/*' base-directory: 'build/test-results/test'
If you are doing UnitTest, it is very useful to measure Code Coverage. You can check if the tests enough coverage your code. You create report groups in the same order that you created UnitTest’s reports group. typing name as
Select Code Coverage for the report type.
Copy the ARN of the Concurrency-Coverage-Report report groups and replace
reports: <Coverage-REPORT-GROUP-ARN>: files: - 'build/jacoco_report/test/jacocoTestReport.xml' file-format: 'JACOCOXML'
this is final code of buildspec.yml.
version: 0.2 phases: install: runtime-versions: java: corretto11 commands: - java -version - gradle -version build: commands: - ./gradlew clean build reports: <YOUR-REPORT-GROUP-ARN>: files: - '**/*' base-directory: 'build/test-results/test' <Coverage-REPORT-GROUP-ARN>: files: - 'build/jacoco_report/test/jacocoTestReport.xml' file-format: 'JACOCOXML' artifacts: files: - '**/*' name: concurrencysample-$(date +%Y-%m-%d)
Commit and push them to codecommit.
cd amazon-cicd-concurrency-sample-application git add . git commit -m "change Buildspec.yml" git push
let’s check if the changes have been reflected. Select concurrencysample by selecting Build projects in Build on the left menu.
You can see the failed build. let’s click on the content to confirm. If you look at the message below, you can see that the build was successful. But you can see UnitTest failed. In this way, it is difficult to see the details of how and what tests have passed. so you can see to the report file generated in the build folder or view the xml file. But you can easily check the results of each build by using the previously linked CodeBuild Report. let’s go Report groups and check the uploaded report.
Select Report groups from the left Build menu. Then select the Concurrency-Unittest-Report you created earlier.
You can see the success and execution time in a graph and click the report in the report history at the bottom to see the details of UnitTest. It is much more easy to check than the console.
Now let’s check the Code Coverage. As before, select Report groups from the left Build menu. And select the Concurrency-Coverage-Report you created earlier.
You can check a report on how well enough of the tests are coverage your code. You can check Coverage trend by Line or Branch.
Modifying build.gradle may cause build failure if it does not exceed a certain coverage. (Currently, it is set to pass if it more 20%.)