0
0
JUnittesting~5 mins

Selecting tests by tags and classes in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of using tags in JUnit tests?
Tags help group tests so you can run specific sets of tests based on their category or purpose, like 'fast' or 'database'.
Click to reveal answer
beginner
How do you tag a test method in JUnit 5?
Use the @Tag annotation above the test method, for example: <br> @Tag("fast")<br>void testQuick() { ... }
Click to reveal answer
intermediate
What is the difference between selecting tests by tags and by classes in JUnit?
Selecting by tags runs tests marked with specific tags anywhere in your code. Selecting by classes runs all tests inside specific test classes.
Click to reveal answer
intermediate
How can you run tests from a specific class using the JUnit Console Launcher?
Use the option --select-class=your.package.YourTestClass to run all tests in that class.
Click to reveal answer
advanced
Why is it useful to combine tags and classes when selecting tests?
Combining tags and classes lets you run very specific tests, like only 'slow' tests in a certain class, saving time and focusing on relevant tests.
Click to reveal answer
Which annotation is used to tag tests in JUnit 5?
A@TestCategory
B@Category
C@Tag
D@TestTag
How do you run tests with the tag 'integration' using the JUnit Console Launcher?
A--include-tag integration
B--select-tag integration
C--tags integration
D--filter-tag integration
What happens if you select tests by class name in JUnit?
ARuns tests only if they have no tags
BRuns only tagged tests in that class
CRuns tests in all classes with similar names
DRuns all tests inside that class
Can you combine multiple tags when selecting tests in JUnit?
AYes, you can include multiple tags
BNo, only one tag at a time
COnly if tags are numeric
DOnly if tags are in the same package
Which command runs all tests in the class 'com.example.MyTests'?
A--run-class com.example.MyTests
B--select-class com.example.MyTests
C--include-class com.example.MyTests
D--class-name com.example.MyTests
Explain how you would use tags and classes to run only a subset of tests in a large JUnit project.
Think about grouping tests by purpose and location.
You got /4 concepts.
    Describe the benefits of selecting tests by tags compared to selecting by classes.
    Consider how tests are organized and run.
    You got /4 concepts.