0
0
JUnittesting~20 mins

Maven Surefire plugin in JUnit - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Surefire Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Surefire Plugin Default Test Inclusion

Given the following Maven Surefire plugin configuration snippet, which test classes will be executed by default?

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>3.0.0-M7</version>
</plugin>
AAll classes in the src/main/java directory
BOnly classes named exactly Test.java
COnly classes annotated with @RunWith
DAll classes matching **/Test*.java, **/*Test.java, and **/*Tests.java
Attempts:
2 left
💡 Hint

Think about the default naming patterns Surefire uses to find test classes.

assertion
intermediate
2:00remaining
Surefire Plugin Failsafe vs Surefire

Which assertion about the Maven Surefire and Failsafe plugins is correct?

ASurefire runs unit tests during the test phase; Failsafe runs integration tests during the integration-test phase
BFailsafe runs unit tests during the test phase; Surefire runs integration tests during the integration-test phase
CBoth Surefire and Failsafe run tests only during the package phase
DSurefire runs tests only if the project uses JUnit 5
Attempts:
2 left
💡 Hint

Consider the Maven lifecycle phases and typical plugin usage.

🔧 Debug
advanced
2:00remaining
Debugging Surefire Test Skipping

A developer notices that no tests run when executing mvn test even though test classes exist. The Surefire plugin is configured as below:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>3.0.0-M7</version>
  <configuration>
    <skipTests>true</skipTests>
  </configuration>
</plugin>

What is the reason tests are not running?

AThe <code>skipTests</code> parameter is set to true, so Surefire skips all tests
BTests are skipped because the <code>test</code> phase is not bound to Surefire by default
CThe plugin version 3.0.0-M7 does not support running tests
DTests are skipped because the test classes are not in the default directory
Attempts:
2 left
💡 Hint

Check the plugin configuration parameters related to skipping tests.

framework
advanced
2:00remaining
Surefire Plugin and JUnit 5 Support

Which configuration is required to enable JUnit 5 tests to run with Maven Surefire plugin version 3.0.0-M7?

ANo additional configuration is needed; Surefire 3.0.0-M7 supports JUnit 5 by default
BAdd <code>&lt;dependency&gt;org.junit.jupiter:junit-jupiter-engine&lt;/dependency&gt;</code> and configure Surefire to use <code>junitPlatform</code> provider
CUse the Failsafe plugin instead of Surefire for JUnit 5 tests
DAdd <code>&lt;dependency&gt;junit:junit&lt;/dependency&gt;</code> to support JUnit 5
Attempts:
2 left
💡 Hint

Think about the provider and dependencies needed for JUnit 5.

🧠 Conceptual
expert
2:00remaining
Surefire Plugin Parallel Test Execution

Which statement about configuring parallel test execution in Maven Surefire plugin is correct?

ASetting <code>parallel</code> to <code>classes</code> runs test classes sequentially
BParallel execution is not supported by Surefire plugin
CSetting <code>parallel</code> to <code>methods</code> runs test methods in parallel within the same class
DSurefire requires external tools to run tests in parallel
Attempts:
2 left
💡 Hint

Consider the parallel modes Surefire supports.