How To Execute Classes and Packages in JUnit 5 | JUnit 5 Tutorial
In Part 8 of the JUnit 5 Testing tutorial series, join πΉππ π±ππππ (@RexJonesII), an experienced QA Engineer, Trainer, YouTuber, and Blogger, as he dives deep into executing classes and packages in JUnit 5 using Maven. Youβll learn how to run all classes and packages and target a specific class and package for faster and more efficient workflows.
Rex also covers practical Maven commands, patterns, and configurations to make your testing more efficient and targeted.
00:01 Introduction
01:24 Executing Classes in JUnit 5
22:47 Executing Packages in JUnit 5
27:46 Configuring pom.xml for Test Execution
31:50 Closing
This session focuses on executing JUnit 5 test scenarios using Maven, providing a comprehensive overview of running individual classes, multiple classes, and packages efficiently. The instructor explains that JUnit 5 allows executing all tests, a specific class, or a package, which helps improve development workflow by providing fast feedback on targeted areas.
Maven is emphasized as the preferred build tool, with the Surefire plugin (version 2.22 or higher) being essential for running tests. The session demonstrates configuring the pom.xml file, updating plugin versions, and using the terminal to run tests with commands like mvn clean test or mvn test -Dtest=ClassName, highlighting the importance of exact class names and the option to use fully qualified package names.
The video details Mavenβs handling of test patterns and naming conventions, including classes ending with Test, Tests, or TestCase, and how to execute multiple classes or patterns using wildcards and comma-separated patterns. Special attention is given to verbose output using the -X flag, which provides detailed error and failure information for debugging. The instructor shows how to run tests selectively by including or excluding specific classes, including the use of exclamation marks (!) in patterns to exclude classes from execution.
Executing packages is also covered, both through the IDE and the command line, using wildcards to include all classes in a package or multiple packages with the comma as an βorβ operator. The session further explains configuring includes and excludes directly in the Maven Surefire plugin within pom.xml for more permanent control, with guidance on avoiding conflicts by placing exclude before include when both are used. The demonstration highlights practical examples, including troubleshooting failed or skipped tests, handling timeout errors, and executing multiple patterns to cover diverse testing scenarios.
By the end of the session, viewers learn a systematic approach to execute JUnit 5 tests efficiently, whether targeting a single class, multiple classes, or entire packages, and how to configure Maven for precise control over test execution. The session concludes with pointers to LambdaTest blogs, community resources, and certification programs for further learning and professional recognition.
Rex Jones II
Rex is an Experienced Quality Assurance (QA) Engineer with a history of working in the IT and Services industry. Certified as a Certified Software Test Engineer (CSTE) and Test Management Approach (TMap). Also skilled in Automation, Agile Methodologies, Test Strategies, and Software Development Life Cycle (SDLC) with a passion for testing software manually or automation such as Selenium.