Challenge - 5 Problems
Tag & Class Test Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of JUnit test run with tag filter
Given the following JUnit 5 test classes with tags, what will be the output when running tests with the tag
@Tag("fast") only?JUnit
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; public class FastTests { @Test @Tag("fast") void fastTest1() { assertTrue(true); } @Test @Tag("slow") void slowTest1() { assertTrue(true); } } public class MixedTests { @Test @Tag("fast") void fastTest2() { assertTrue(true); } @Test void noTagTest() { assertTrue(true); } }
Attempts:
2 left
💡 Hint
Remember that JUnit 5 allows filtering tests by tags using the @Tag annotation and test runners can include or exclude tests by tag.
✗ Incorrect
When running tests filtered by the tag "fast", only tests annotated with @Tag("fast") will run. Tests with other tags or no tags are skipped.
❓ assertion
intermediate1:30remaining
Correct assertion to verify only tagged tests ran
You run JUnit tests filtered by tag "integration". Which assertion correctly verifies that only tests with this tag ran?
JUnit
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; // Assume testResults is a list of test names that ran List<String> testResults = List.of("integrationTest1", "integrationTest2");
Attempts:
2 left
💡 Hint
Count how many tests have the "integration" tag and expect only those to run.
✗ Incorrect
If only tests tagged "integration" run, and there are exactly two such tests, the size of testResults should be 2.
🔧 Debug
advanced2:00remaining
Why does filtering by tag fail to exclude untagged tests?
You configured your JUnit 5 test run to include only tests with tag "ui" but untagged tests still run. What is the most likely cause?
Attempts:
2 left
💡 Hint
Check your test runner or build tool configuration for tag filtering settings.
✗ Incorrect
JUnit 5 supports tag filtering, but the runner must be explicitly configured to include or exclude tags. Without this, all tests run.
❓ framework
advanced1:30remaining
Selecting tests by class and tag in JUnit 5
Which JUnit 5 command line option runs only tests in class
LoginTests tagged with smoke?Attempts:
2 left
💡 Hint
Use --select-class to specify the test class and --include-tags to filter by tag.
✗ Incorrect
The option --select-class=LoginTests selects that class, and --include-tags=smoke filters tests to only those tagged "smoke".
🧠 Conceptual
expert2:30remaining
Impact of multiple tags on test selection
If a test method is annotated with
@Tag("fast") and @Tag("database"), and the test run includes only tests tagged "fast", what happens?Attempts:
2 left
💡 Hint
Think about how tag filters include tests that have at least one matching tag.
✗ Incorrect
JUnit 5 includes tests that have any of the included tags. Having multiple tags does not exclude a test if one tag matches the filter.