0
0
JUnittesting~20 mins

Package-level test organization in JUnit - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Package Test Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why organize tests at the package level?

In JUnit testing, what is the main advantage of organizing tests at the package level?

AIt automatically generates test data for all classes in the package.
BIt allows running all tests in a package together, improving test management and reporting.
CIt prevents tests from accessing classes outside their package, increasing security.
DIt forces tests to be run only one by one, reducing parallel execution.
Attempts:
2 left
💡 Hint

Think about how grouping tests helps when running many tests.

Predict Output
intermediate
2:00remaining
JUnit package-level test suite execution result

Given this JUnit 5 package-level test suite setup, what will be the output when running the suite?

JUnit
package com.example.tests;

import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.Suite;

@Suite
@SelectPackages("com.example.tests.unit")
public class UnitTestsSuite {
}

// Assume com.example.tests.unit contains 3 test classes each with 2 tests, all passing.
AThe suite runs only one test from each class, total 3 tests.
BThe suite runs no tests because @SelectPackages is ignored at class level.
CThe suite runs all 6 tests from the 3 classes and reports all passed.
DThe suite runs tests but reports failures due to missing @Test annotations.
Attempts:
2 left
💡 Hint

Check how @SelectPackages works with @Suite in JUnit 5.

locator
advanced
2:00remaining
Best locator for package-level test suite class

Which of the following is the best Java package and class name for a package-level test suite that runs all tests in com.app.services?

Acom.app.services.ServiceTestSuite
Bcom.app.AllServicesSuite
Ccom.app.services.testsuite
Dcom.app.services.AllServicesTests
Attempts:
2 left
💡 Hint

Consider Java naming conventions and clarity for test suite classes.

assertion
advanced
2:00remaining
Assertion to verify package-level test suite runs all tests

In a JUnit 5 test suite that runs all tests in com.example.api, which assertion best verifies that exactly 10 tests were executed?

AassertEquals(10, testExecutionSummary.getTestsFailedCount())
BassertTrue(testExecutionSummary.getTestsFoundCount() == 10)
CassertEquals(10, testExecutionSummary.getTestsSucceededCount())
DassertEquals(10, testExecutionSummary.getTestsStartedCount())
Attempts:
2 left
💡 Hint

Think about which count reflects total tests run, regardless of pass/fail.

framework
expert
2:00remaining
Debugging package-level test suite execution failure

You created a JUnit 5 package-level test suite using @Suite and @SelectPackages("com.app.features"), but no tests run. What is the most likely cause?

AThe package name in @SelectPackages is misspelled or does not match actual package.
BThe suite class is missing the @RunWith annotation.
CThe test classes in com.app.features lack @Test annotations on methods.
DJUnit 5 does not support package-level test suites.
Attempts:
2 left
💡 Hint

Check the package name spelling and case carefully.