CodeBuild Report

let’s Add to CodeBuild Report Group

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

  1. Select Report groups in the right Build tab. Select Create report group at the top right. codebuild02

  2. Enter 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. codebuild02

  3. 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. codebuild02

  4. Now let’s go back to Cloud9 and edit buildspec.yml. buildspec.yml is located in ConcurrencySample’s root directory.

    DataLakeStorage03 Double-click the file to add content. Paste the Report group ARN to <YOUR-REPORT-GROUP-ARN>.

    reports:
      <YOUR-REPORT-GROUP-ARN>:
        files:
          - '**/*'
        base-directory: 'build/test-results/test'
    
  5. 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 Concurrency-Coverage-Report. Select Code Coverage for the report type. codebuild02

  6. Copy the ARN of the Concurrency-Coverage-Report report groups and replace <Coverage-REPORT-GROUP-ARN>.

    reports:
      <Coverage-REPORT-GROUP-ARN>:
        files:
          - 'build/jacoco_report/test/jacocoTestReport.xml'
        file-format: 'JACOCOXML'
    
  7. 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)
    
  8. Commit and push them to codecommit.

    cd amazon-cicd-concurrency-sample-application
    git add .
    git commit -m "change Buildspec.yml"
    git push
    
  9. let’s check if the changes have been reflected. Select concurrencysample by selecting Build projects in Build on the left menu. codebuild02

  10. You can see the failed build. let’s click on the content to confirm. codebuild02 If you look at the message below, you can see that the build was successful. But you can see UnitTest failed. codebuild02 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.

  11. Select Report groups from the left Build menu. Then select the Concurrency-Unittest-Report you created earlier. codebuild02

  12. 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. codebuild02 codebuild02 codebuild02

  13. 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. codebuild02

  14. 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. codebuild02

  15. 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%.)

For more information, please check Codebuild. For information on unit testing and code coverage tools, see Junit, jacoco or other Code Coverage tools. Try searching.