0
0
JUnittesting~20 mins

Maven dependency setup in JUnit - Practice Problems & Coding Challenges

Choose your learning style9 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.