DVA-C02 · Question #492
A company runs continuous integration/continuous delivery (CI/CD) pipelines for its application on AWS CodePipeline. A developer must write unit tests and run them as part of the pipelines before stag
The correct answer is B. Update the AWS CodeBuild build specification to include a phase for running unit tests.. AWS CodeBuild uses a buildspec.yml file with defined phases (install, pre_build, build, post_build) where unit tests can be executed as part of the build stage before artifacts are produced.
Question
A company runs continuous integration/continuous delivery (CI/CD) pipelines for its application on AWS CodePipeline. A developer must write unit tests and run them as part of the pipelines before staging the artifacts for testing. How should the developer incorporate unit tests as part of CI/CD pipelines?
Options
- ACreate a separate CodePipeline pipeline to run unit tests.
- BUpdate the AWS CodeBuild build specification to include a phase for running unit tests.
- CInstall the AWS CodeDeploy agent on an Amazon EC2 instance to run unit tests.
- DCreate a testing branch in a git repository for the pipelines to run unit tests.
How the community answered
(29 responses)- A7% (2)
- B86% (25)
- C3% (1)
- D3% (1)
Why each option
AWS CodeBuild uses a buildspec.yml file with defined phases (install, pre_build, build, post_build) where unit tests can be executed as part of the build stage before artifacts are produced.
Creating a separate pipeline solely to run unit tests adds unnecessary complexity and infrastructure overhead when CodeBuild already supports running tests natively.
CodeBuild's build specification (buildspec.yml) supports a multi-phase build lifecycle. Adding unit test commands to the `build` or `pre_build` phase integrates testing directly into the existing CI/CD pipeline without creating additional pipeline stages or resources, making it the most straightforward approach.
CodeDeploy is a deployment tool, not a build or test tool; installing its agent on EC2 to run unit tests is an architectural misuse of the service.
Creating a testing branch is a source control strategy, not a CI/CD execution mechanism, and does not directly cause unit tests to run within the pipeline.
Concept tested: AWS CodeBuild buildspec phases for unit testing
Source: https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html
Community Discussion
No community discussion yet for this question.