Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewing Unit Test and Coverage Reports Generated in AWS CodeBuild

I am using AWS CodeBuild to run unit tests for my python project using pytest. I am using the --junitxml argument and the pytest-cov package to generate test reports and coverage reports that I've listed as artifacts in my buildspec.yml.

I've used Jenkins in the past to do this and Jenkins provides some nice graphs and tables showing test result history and coverage history as well as results from the most recent test.

Is there a good way to view the reports generated by my CodeBuild project? I haven't found anything in CodeBuild or CodePipeline directly. Do I have to use a separate tool that can ingest the report files? If so, what are some tools for this?

like image 801
Brian Avatar asked Apr 05 '18 05:04

Brian


People also ask

How do I get code coverage results?

Code coverage option is available under the Test menu when you run test methods using Test Explorer. The results table shows the percentage of the code executed in each assembly, class, and procedure. The source editor highlights the tested code.

Which AWS service is used to store the test result files?

AWS CodeBuild announced the launch of a new feature in CodeBuild called Reports. This feature allows you to view the reports generated by functional or integration tests. The reports can be in the JUnit XML or Cucumber JSON format.

How do I find CodeBuild logs?

To see the entire build log in CloudWatch Logs, choose the View entire log link. In the CloudWatch Logs log stream, you can browse the log events. By default, only the last set of log events is displayed. To see earlier log events, scroll to the beginning of the list.

What is contained in an AWS CodeBuild Buildspec file?

A buildspec is a collection of build commands and related settings, in YAML format, that CodeBuild uses to run a build. Without a build spec, CodeBuild cannot successfully convert your build input into build output or locate the build output artifact in the build environment to upload to your output bucket.


1 Answers

CodeBuild recently announced support for test reports. Copied from the blog post:

The reports can be in the JUnit XML or Cucumber JSON format. You can view metrics such as Pass Rate %, Test Run Duration, and number of Passed versus Failed/Error test cases in one location. Builders can use any testing frameworks as long as the reports are generated in the supported formats.


Two things needs to be updated to accomplish this. First, add some configuration to the buildspec.yml file:

reports:
  SurefireReports: # CodeBuild will create a report group called "SurefireReports".
    files: #Store all of the files
      - '**/*'
    base-directory: 'target/surefire-reports' # Location of the reports 

Secondly, CodeBuild needs some additional IAM permissions:

{
    "Statement": [
        {
            "Resource": "arn:aws:codebuild:your-region:your-aws-account-id:report-group/my-project-*", 
            "Effect": "Allow",
            "Action": [
                "codebuild:CreateReportGroup",
                "codebuild:CreateReport",
                "codebuild:UpdateReport",
                "codebuild:BatchPutTestCases"
            ]
        }
    ]
}
like image 199
matsev Avatar answered Oct 02 '22 21:10

matsev