When running with --include-tag fast, only tests tagged with "fast" run.
Step 2: Analyze tags on each test
Class has @Tag("slow"), so by default tests inherit "slow" tag. testA has no method tag, so only "slow" applies. testB and testC have @Tag("fast") overriding or adding to tags.
Step 3: Determine which tests match "fast" tag
Only testB and testC have the "fast" tag, so only these run.
Final Answer:
Only testB and testC -> Option C
Quick Check:
Include tag "fast" runs only tests tagged "fast" [OK]
Hint: Method tags override class tags for filtering [OK]
Common Mistakes:
Assuming class tag applies to all tests ignoring method tags
Thinking all tests run without tag filtering
Confusing include and exclude tag filters
4. You want to run tests only from the class LoginTests but your command mvn test -Dgroups=LoginTests runs no tests. What is the likely problem?
medium
A. The command should be mvn test -Dtest=LoginTests to run by class
B. JUnit 5 uses tags, not groups; the correct filter is by tags or class name
C. You must add @Group annotation to the class for this to work
D. The class name is case-sensitive and must be lowercase
Solution
Step 1: Understand Maven test filtering options
Maven Surefire plugin uses -Dtest=ClassName to run tests by class name, not -Dgroups.
Step 2: Identify correct command to run tests by class
To run tests from LoginTests, use mvn test -Dtest=LoginTests.
Final Answer:
The command should be mvn test -Dtest=LoginTests to run by class -> Option A
Quick Check:
Run by class uses -Dtest=ClassName [OK]
Hint: Use -Dtest=ClassName to run tests by class [OK]
Common Mistakes:
Using -Dgroups which is for TestNG, not JUnit
Assuming class names are lowercase
Expecting @Group annotation in JUnit
5. You have two test classes: FastTests tagged with @Tag("fast") and SlowTests tagged with @Tag("slow"). You want to run all tests except those tagged "slow" and only from classes whose names end with "Tests". Which command correctly runs this selection?
hard
A. junit-platform-console --exclude-tag slow --exclude-classname .*Tests
B. junit-platform-console --include-tag fast --include-classname .*Tests
C. junit-platform-console --include-tag slow --include-classname FastTests
D. junit-platform-console --exclude-tag slow --include-classname .*Tests
Solution
Step 1: Understand tag and class name filters
To exclude slow tests, use --exclude-tag slow. To include only classes ending with "Tests", use --include-classname .*Tests regex.
Step 2: Analyze each option
junit-platform-console --exclude-tag slow --include-classname .*Tests excludes slow tags and includes classes matching .*Tests, which matches both FastTests and SlowTests classes but excludes slow-tagged tests.
Step 3: Confirm correct filtering
junit-platform-console --include-tag fast --include-classname .*Tests includes only fast tags, which works but excludes any untagged tests. junit-platform-console --exclude-tag slow --exclude-classname .*Tests excludes classes ending with Tests, which is opposite of requirement. junit-platform-console --include-tag slow --include-classname FastTests includes slow tags, which is opposite of requirement.
Final Answer:
junit-platform-console --exclude-tag slow --include-classname .*Tests -> Option D
Quick Check:
Exclude slow tag + include class regex = junit-platform-console --exclude-tag slow --include-classname .*Tests [OK]
Hint: Exclude slow tag and include class regex for correct filtering [OK]
Common Mistakes:
Using include-tag slow instead of exclude-tag
Excluding classes instead of including
Confusing include-tag and exclude-tag usage
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.