Bird
Raised Fist0
JUnittesting~20 mins

Maven dependency setup in JUnit - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Maven JUnit Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
JUnit 5 Maven Dependency Output
What will happen if you run a JUnit 5 test with the following Maven dependency setup in your pom.xml?
JUnit
<dependency>
  <groupId>org.junit.jupiter</groupId>
  <artifactId>junit-jupiter-api</artifactId>
  <version>5.9.2</version>
  <scope>test</scope>
</dependency>
ABuild fails because the <scope>test</scope> is invalid for JUnit dependencies.
BTests run successfully with JUnit 5 features available.
CTests fail to run because the <artifactId> is incorrect for JUnit 5.
DTests run but only with JUnit 4 features, not JUnit 5.
Attempts:
2 left
💡 Hint
Check if the dependency includes the correct groupId, artifactId, and version for JUnit 5.
❓ assertion
intermediate
2:00remaining
Correct Assertion for Maven Dependency Presence
Which assertion correctly verifies that the JUnit 5 dependency is included in the Maven project during a build?
AassertFalse(project.getDependencies().contains("junit-jupiter-api"));
BassertEquals("junit-jupiter-api", project.getDependencies().get(0).getGroupId());
CassertTrue(project.getDependencies().stream().anyMatch(d -> d.getArtifactId().equals("junit-jupiter-api")));
DassertNull(project.getDependencies().stream().filter(d -> d.getArtifactId().equals("junit-jupiter-api")).findFirst());
Attempts:
2 left
💡 Hint
Look for an assertion that checks if any dependency has the correct artifactId.
🔧 Debug
advanced
2:00remaining
Debugging Missing JUnit 5 Dependency Error
You added the JUnit 5 dependency in your pom.xml but Maven reports: Cannot find symbol: @Test when running tests. What is the most likely cause?
AThe dependency is declared in the <dependencies> section but not in the <build> plugins.
BThe JUnit 5 dependency version is too old and does not support @Test annotation.
CThe <artifactId> is set to 'junit-jupiter-engine' instead of 'junit-jupiter-api'.
DThe <scope>test</scope> is missing, so the dependency is not included during test compilation.
Attempts:
2 left
💡 Hint
Check if the dependency is available during the test phase.
🧠 Conceptual
advanced
2:00remaining
Understanding Maven Dependency Scopes for Testing
Which Maven dependency scope is best suited for JUnit 5 dependencies and why?
A<scope>test</scope> because it includes the dependency only during testing and not in the final build artifact.
B<scope>compile</scope> because tests need the dependency during compilation and runtime.
C<scope>runtime</scope> because the dependency is only needed when running tests, not compiling.
D<scope>provided</scope> because the dependency is provided by the JDK during tests.
Attempts:
2 left
💡 Hint
Think about when test dependencies are needed in the build lifecycle.
❓ framework
expert
3:00remaining
Maven Surefire Plugin Configuration for JUnit 5
Which Maven Surefire plugin configuration snippet correctly enables running JUnit 5 tests?
JUnit
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>3.0.0-M7</version>
  <!-- Configuration here -->
</plugin>
A
&lt;configuration&gt;
  &lt;providers&gt;
    &lt;provider&gt;
      &lt;name&gt;junit-platform&lt;/name&gt;
    &lt;/provider&gt;
  &lt;/providers&gt;
&lt;/configuration&gt;
B
&lt;configuration&gt;
  &lt;useModulePath&gt;false&lt;/useModulePath&gt;
&lt;/configuration&gt;
C
&lt;configuration&gt;
  &lt;includes&gt;
    &lt;include&gt;**/*Test.java&lt;/include&gt;
  &lt;/includes&gt;
&lt;/configuration&gt;
D
&lt;configuration&gt;
  &lt;testSourceDirectory&gt;src/test/java&lt;/testSourceDirectory&gt;
&lt;/configuration&gt;
Attempts:
2 left
💡 Hint
JUnit 5 requires the Surefire plugin to use the junit-platform provider.

Practice

(1/5)
1. What is the main purpose of adding a JUnit dependency in the pom.xml file of a Maven project?
easy
A. To include JUnit libraries automatically for running tests
B. To compile the main application code
C. To deploy the application to a server
D. To create a new Maven project

Solution

  1. Step 1: Understand Maven dependency role

    Maven dependencies add external libraries to the project automatically.
  2. Step 2: Identify JUnit dependency purpose

    JUnit dependency specifically adds testing libraries to run unit tests.
  3. Final Answer:

    To include JUnit libraries automatically for running tests -> Option A
  4. Quick Check:

    Maven dependency = add libraries [OK]
Hint: JUnit dependency adds test libraries automatically [OK]
Common Mistakes:
  • Confusing dependency with deployment
  • Thinking dependency compiles main code
  • Assuming dependency creates projects
2. Which of the following is the correct way to add JUnit 5 dependency in pom.xml with scope set to test?
easy
A. \n org.junit.jupiter\n junit-jupiter\n 5.9.2\n
B. \n org.junit.jupiter\n junit-jupiter\n 5.9.2\n test\n
C. \n org.junit.jupiter\n junit-jupiter\n compile\n 5.9.2\n
D. \n org.junit.jupiter\n junit-jupiter-api\n 5.9.2\n test\n

Solution

  1. Step 1: Check groupId and artifactId for JUnit 5

    The standard JUnit 5 dependency uses org.junit.jupiter and junit-jupiter.
  2. Step 2: Verify scope is set to test

    Scope must be test to limit usage to testing phase.
  3. Final Answer:

    Correct dependency with groupId, artifactId, version, and test scope -> Option B
  4. Quick Check:

    JUnit 5 dependency + test scope = \n org.junit.jupiter\n junit-jupiter\n 5.9.2\n test\n [OK]
Hint: Always set test for test dependencies [OK]
Common Mistakes:
  • Omitting the test tag
  • Using wrong artifactId like junit-jupiter-api
  • Setting scope to compile instead of test
3. Given this pom.xml snippet, what will happen when you run mvn test?
<dependency>
  <groupId>org.junit.jupiter</groupId>
  <artifactId>junit-jupiter</artifactId>
  <version>5.9.2</version>
  <scope>test</scope>
</dependency>
medium
A. JUnit 5 tests will run successfully using the added dependency
B. Tests will fail because the dependency scope is wrong
C. Maven will ignore the dependency and not run tests
D. Compilation will fail due to missing JUnit classes

Solution

  1. Step 1: Understand scope test effect

    Scope test means dependency is available only during testing phase.
  2. Step 2: Running mvn test uses test scope dependencies

    Maven includes JUnit 5 library during test execution, so tests run fine.
  3. Final Answer:

    JUnit 5 tests will run successfully using the added dependency -> Option A
  4. Quick Check:

    Scope test + mvn test = tests run [OK]
Hint: Scope test means dependency active only during tests [OK]
Common Mistakes:
  • Thinking test scope excludes dependency during tests
  • Confusing compile scope with test scope
  • Assuming tests run without dependencies
4. You added this dependency to pom.xml but your tests fail with ClassNotFoundException for JUnit classes. What is the likely problem?
<dependency>
  <groupId>org.junit.jupiter</groupId>
  <artifactId>junit-jupiter-api</artifactId>
  <version>5.9.2</version>
</dependency>
medium
A. Dependency must be added in settings.xml not pom.xml
B. Missing <scope>test</scope> causes dependency not to load
C. Version 5.9.2 is incompatible with Maven
D. Using junit-jupiter-api alone is insufficient for tests

Solution

  1. Step 1: Identify artifactId usage

    junit-jupiter-api provides only the test API, not the engine.
  2. Step 2: Recognize missing JUnit engine dependency

    Tests need junit-jupiter which bundles API and engine.
  3. Final Answer:

    Using junit-jupiter-api alone is insufficient for tests -> Option D
  4. Quick Check:

    Missing JUnit engine causes ClassNotFoundException [OK]
Hint: Use junit-jupiter for full JUnit 5, not just api [OK]
Common Mistakes:
  • Assuming api artifact is enough
  • Ignoring missing scope tag
  • Thinking version causes ClassNotFoundException
5. You want to add JUnit 5 to your Maven project but only for running tests, not for compiling main code. Which is the best complete dependency snippet to add in pom.xml?
hard
A. org.junit.vintage junit-vintage-engine 5.9.2 test
B. org.junit.jupiter junit-jupiter-engine 5.9.2 compile
C. org.junit.jupiter junit-jupiter 5.9.2 test
D. org.junit.jupiter junit-jupiter-api 5.9.2 runtime

Solution

  1. Step 1: Identify full JUnit 5 dependency

    The junit-jupiter artifact includes API and engine for tests.
  2. Step 2: Confirm scope for test-only usage

    Setting scope to test ensures dependency is used only during testing.
  3. Final Answer:

    Complete JUnit 5 dependency with test scope -> Option C
  4. Quick Check:

    JUnit 5 + test scope = org.junit.jupiter junit-jupiter 5.9.2 test [OK]
Hint: Use junit-jupiter with scope test for proper test setup [OK]
Common Mistakes:
  • Using compile or runtime scope instead of test
  • Using only junit-jupiter-engine or vintage-engine
  • Confusing API artifact with full junit-jupiter
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard