0
0
JUnittesting~10 mins

Selecting tests by tags and classes in JUnit - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to run only tests tagged with "fast" using JUnit 5.

JUnit
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
    .selectors(DiscoverySelectors.selectClass(MyTests.class))
    .filters(TagFilter.includeTags("[1]"))
    .build();
Drag options to blanks, or click blank then click option'
Aintegration
Bfast
Cslow
Dunit
Attempts:
3 left
💡 Hint
Common Mistakes
Using a tag name that doesn't exist in the tests.
Using excludeTags instead of includeTags.
2fill in blank
medium

Complete the code to select tests from the class named "CalculatorTests".

JUnit
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
    .selectors(DiscoverySelectors.[1](CalculatorTests.class))
    .build();
Drag options to blanks, or click blank then click option'
AselectClass
BselectModule
CselectMethod
DselectPackage
Attempts:
3 left
💡 Hint
Common Mistakes
Using selectPackage which selects all classes in a package.
Using selectMethod which selects a single test method.
3fill in blank
hard

Fix the error in the code to exclude tests tagged with "slow".

JUnit
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
    .selectors(DiscoverySelectors.selectClass(MyTests.class))
    .filters(TagFilter.[1]Tags("slow"))
    .build();
Drag options to blanks, or click blank then click option'
Ainclude
Bfilter
Cexclude
Dselect
Attempts:
3 left
💡 Hint
Common Mistakes
Using includeTags which runs only the tagged tests.
Using a non-existent method like filterTags.
4fill in blank
hard

Fill both blanks to select tests from package "com.example" and include only tests tagged "integration".

JUnit
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
    .selectors(DiscoverySelectors.[1]("com.example"))
    .filters(TagFilter.[2]Tags("integration"))
    .build();
Drag options to blanks, or click blank then click option'
AselectPackage
Binclude
Cexclude
DselectClass
Attempts:
3 left
💡 Hint
Common Mistakes
Using selectClass instead of selectPackage for package selection.
Using excludeTags instead of includeTags.
5fill in blank
hard

Fill all three blanks to select a test method "testAdd" in class "MathTests" and exclude tests tagged "slow".

JUnit
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
    .selectors(DiscoverySelectors.[1](MathTests.class, "[2]"))
    .filters(TagFilter.[3]Tags("slow"))
    .build();
Drag options to blanks, or click blank then click option'
AselectClass
BselectMethod
Cexclude
DtestAdd
Attempts:
3 left
💡 Hint
Common Mistakes
Using selectClass instead of selectMethod for a single test method.
Using includeTags instead of excludeTags.