Testing / JUnit6 Interview Questions
What is the @Suite API in JUnit 6 and how do you group tests into suites?
JUnit 6 provides a @Suite annotation (in junit-platform-suite) for declaratively grouping tests from multiple classes or packages. This replaces JUnit 4's @RunWith(Suite.class) and JUnit Platform Runner (which was removed in JUnit 6).
import org.junit.platform.suite.api.*; // Basic suite: select specific test classes @Suite @SelectClasses({ OrderServiceTest.class, PaymentServiceTest.class, InventoryServiceTest.class }) class SmokeTestSuite {} // Suite by package (runs all tests in the package) @Suite @SelectPackages({"com.example.unit", "com.example.integration"}) class AllTestsSuite {} // Suite with tag filtering @Suite @SelectPackages("com.example") @IncludeTags("fast") @ExcludeTags({"slow", "integration"}) class FastTestSuite {} // Suite with class name pattern @Suite @SelectPackages("com.example") @IncludeClassNamePatterns(".*IT") // only classes ending in IT class IntegrationTestSuite {} // Maven: run suites explicitly // <configuration> // <includes> // <include>**/*Suite.class</include> // </includes> // </configuration>
Important: suite classes themselves contain no test methods. They are purely declarative configuration classes. The @Suite annotation is a signal to the JUnit Platform to aggregate and run the selected tests.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
