Courseiva
SDLC Automation →hardMultiple Choice

DOP-C02 SDLC Automation Practice Question

A company uses AWS CodeBuild to run builds for a Java application. The buildspec includes a 'mvn test' command. The build succeeds but the tests fail. The team wants to fail the build if any test fails. What should they do?

⚠ Common exam trap

Many candidates confuse the 'post_build' phase with a phase that can retroactively fail the build, or invent a 'test' phase that does not exist in CodeBuild's buildspec schema.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

Ensure the buildspec's 'build' phase includes the test command and that the command returns a non-zero exit code on failure.

CodeBuild determines build success or failure based on the exit code of commands in the buildspec. The 'mvn test' command returns a non-zero exit code when tests fail, which causes the build to fail if placed in the 'build' phase. By ensuring the test command is in the 'build' phase and not suppressed (e.g., with '|| true'), the build will fail on test failure.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    Add a 'post_build' phase that fails the build if tests fail.

    Why it's wrong here

    CodeBuild's post_build phase executes only after the build phase has already completed, so placing test failure detection there cannot prevent the build phase from completing. More importantly, if tests run in post_build and fail, the build will still fail overall, but you have already executed packaging/artifact steps that depend on a successful build. Tests should run in the build phase (or pre_build) so their non-zero exit status aborts the build as early as possible.

  • ✗

    Add a 'test' phase in the buildspec before the 'build' phase.

    Why it's wrong here

    CodeBuild currently only supports the lifecycle phases install, pre_build, build, and post_build; a custom 'test' phase is not a valid buildspec phase and will cause a validation/build failure or be ignored, not run your tests. Even if you inserted test commands in pre_build or build before the compile step, moving them earlier does not automatically make failures fatal — the shell command still needs to return a non-zero exit code. The 'test' phase is a concept from other CI systems (e.g., Travis CI), not CodeBuild.

  • ✓

    Ensure the buildspec's 'build' phase includes the test command and that the command returns a non-zero exit code on failure.

    Why this is correct

    The correct approach is to run the test command (for example, mvn test or gradle test) inside the build phase of the buildspec. CodeBuild executes each command in a shell where a non-zero exit code causes that phase to be marked failed and the overall build to be FAILED. Because Maven/Gradle test goals already return non-zero when tests fail, this single change ensures the build pipeline stops immediately. Any subsequent build phases, such as post_build artifact packaging, still run, but the final build status will reflect the failure.

  • ✗

    Configure the build project to use batch builds.

    Why it's wrong here

    Batch builds are a CodeBuild feature for running multiple builds concurrently — often called build groups — to speed up execution; they do not alter the exit-code semantics of any individual command in the buildspec. Simply enabling batch builds will not run your Java unit tests automatically, nor will it fail the build when tests fail. Each build in a batch still needs an explicit test command in its buildspec that returns non-zero, and a batch can even succeed at the batch level while an individual build fails, depending on the batch configuration.

About these practice questions

Courseiva writes every DOP-C02 question from scratch — 1,298 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This DOP-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DOP-C02 exam.