DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. JUnit 5 Deep Dive Using Test-Driven Development [Video]

JUnit 5 Deep Dive Using Test-Driven Development [Video]

Learn how to use JUnit 5 for unit testing with the test-driven development approach.

Tarun Telang user avatar by
Tarun Telang
CORE ·
Oct. 18, 18 · Tutorial
Like (3)
Save
Tweet
Share
6.00K Views

Join the DZone community and get the full member experience.

Join For Free

Please find below a video of a deep dive session on JUnit 5. In this session, I have described the new features of JUnit 5 and how can it help in writing code using Test-Driven Development (TDD) methodology.

Prerequisites

  • You should have Spring Tools Suite (STS) 4 or Eclipse IDE installed on your laptop with JDK 8 or above installed.
  • Basic understanding of the philosophy behind unit tests.

Note: For maximum benefit from this session, you can try out the steps together with this video.


Below are the key steps involved in Test-Driven Development.

First, the developer writes the unit tests to cover the new functionality under development. Obviously, these tests would fail to start with but still, the developer should run these unit tests to ensure it fails as expected (not due to some other reasons).

Then he implements the code to make the unit tests pass. The developer might need to go through multiple iterations of writing and running the tests until all the tests are green.

Once the implementation for the desired functionality is complete (signaled by all the tests running successfully). The developer can refactor the code to ensure it is clean to easily support further development on top of it. After refactoring, the developer re-runs the unit tests to ensure all still all tests are passing.

The developer may also refactor the unit test code in case needed. But as a best practice, he should deliberately make it purposefully fail to ensure no false positives are introduced as part of this exercise. 

The entire cycle of steps mentioned above can be repeated for each new functionality to be implemented.

Following are some of the key benefits of this test-driven development.

  • This approach makes sure it is NOT possible for developers to write untestable code.

  • The unit tests provide the much-needed support for refactoring, which is very important to ensure the source code always remains clean and new requirements or changes to the existing functionality can be delivered smoothly forever.

unit test Test-driven development JUnit

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Beginners’ Guide to Run a Linux Server Securely
  • GPT-3 Playground: The AI That Can Write for You
  • The Data Leakage Nightmare in AI
  • Top 5 PHP REST API Frameworks

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: