TDD & Junit 5
Estimated time to read: 2 minutes
From TDD with JUnit 5¶
Introduction¶
Benefits of Test-Driven Development¶
- Drive by clear goals
- Safer code
- Isolate incorrect code
- Easily introduce new functionality
- Documentation for the application
Ask yourself¶
Is your application doing what it is supposed to do? If the application has been manually tested many times by different users you may have some certainty that it is working the expected way. However, how much time will be needed and how many people may be involved to do the testing?
What about the newly-introduced features? When will these be verified? This could take weeks or even months whilst the code is reviewed and tested again.
Classical Code Production Lifecycle¶
In a classical approach; code is written, tested by observing its behaviour and then debugged if it is not working as expected. This cycle continues until the application production is completed.
This can be a tedious process as scenarios are tested again and again after a code change.
If a bug has been discovered, isolating code that causes a bug can prove difficult.
Which piece of code produced the bug? How do we isolate the code that produced the bug? Where do we even start?!
If a request for new functionality is requested, the functionality needs to be understood by the developer before implementation.
What behavior must be followed?
Designing tests that implement the desired outcome assist with the development of code that achieves those goals. This is in fact one of the fundamental principles of test-driven development.