Piyush Rahate
A passionate Lean-Agile Coach with over 19 years of varied experience, I work with professionals, t... Read more
A passionate Lean-Agile Coach with over 19 years of varied experience, I work with professionals, t... Read more
One of the principles of a manifesto for agile software development states that - Continuous attention to technical excellence and good design enhances agility.
But how do we focus on technical excellence? Well, for that we need to explore a bunch of good and useful technical practices. One such practice is Test Driven Development or TDD.
In this article, I would walk you through a simple example of creating a Test-Driven code and elaborate a bit about the practice and associated advantages.
TDD or Test-Driven Development is a common practice for developing code that is simple, maintainable, and well-tested. The approach states that one should write “implementation code” only if there is a “failing test case”.
It is an iterative approach for developing software products where -
Discover the importance of Team and Technical Agility in scaling Agile practices. Learn how to foster adaptability, collaboration, quality, and innovation across your organization to deliver value to customers faster, more reliably, and with higher quality.
Know More!Let us consider a user profile management system that allows users to create a username and password for future authentication. There are certain business rules which the username and password should follow to be valid.
For the sake of simplicity and brevity of the article, I will work with only one rule for the username and that would be to validate the minimum length of the username. Let us say that the minimum length for a username is 8 characters. Now we will start developing our tests and code accordingly. I will be using Laravel and PHPUnit for the code examples.
And we get an error which is quite expected since till now we have not yet created the “ValidatorService” class.
Let us create the class and run the test again. Remember, we are writing just enough code to ensure the failing test case passes. An error is also a failure, so we will write just enough code to make the error go away.
Oh, an error still exists. But now it is different. As expected, now it is looking for the function, which is still not there. Let’s create a placeholder function and execute the test.
And, now we have a failing test case. We will now create the actual code for the functionality to validate the length of the username and execute the test case. The failing test case should now pass.
And it does. Let’s add one more similar test and see if that also passes. It should.
And, yes we have two passing test cases. Let’s add a more generic test case now and execute it.
And all three test cases have now passed. But look at the code it looks like a lot of repetition. Seems like it is now time to “Refactor” our code. PHPUnit provides a nice feature called “data provider” which makes this pretty simple.
Let’s execute the tests and see if they still pass.
And, yes the test cases are still passing. Let us quickly refactor the implementation code as well.
And, do the test cases still pass? Yes, they do. That means for now our code is in quite good shape.
We can now keep adding more test cases to validate different business rules as needed and keep refactoring the code as and when needed. And the moment we will run our test harness, we will know if something is broken because of the new changes that we add.
Running the Team and Technical Agility assessment is simpler than you think. Learn how to conduct it effectively and leverage the results to drive improvement effortlessly.
Unlock Your Potential.As with any other technical discipline, TDD requires a lot of patience and perseverance to become an expert. Although, once you master it, it becomes a habit that reaps huge benefits.
It helps you to create more maintainable, reliable code and also creates a shorter feedback loop if something goes wrong as you build your product.
A passionate Lean-Agile Coach with over 19 years of varied experience, I work with professionals, teams and organizations helping them in their pursuit of agility. Being a Professional Scrum Trainer (Scrum.org), SPC (5.0, Scaled Agile), and ICAgile Authorized Instructor.
WhatsApp UsI recently concluded my PSM 1 training from Agilemania with Piyush being the instructor. I have had multiple trainings before but this one was very different - Good different. For many reasons : 1. Piyush’s content delivery was by far the best I have seen. This tells he has done this many times or to be short, is an expert at this. 2. Unique way to present. I won’t break the surprise but there were no slides or ppt's during the training. And yet, it was so engaging, I felt as active throughout as at the start. This also gave me inspiration to do something different when it comes to your presentation. 3. Different types of activities in breakout rooms. This gave me the opportunity to interact with fellow trainees like myself who were there to learn. You got to try out those. P.S. - there will be always a catch. 4. Full of real life examples. Piyush gave real life examples from his experience that helped me to understand the concepts better. 5. Lastly, there were optimum breaks in 2 days that helped me to remain focused throughout. When I was choosing the trainer for PSM 1 from Scrum.org, I read a lot of reviews for many trainers. I chose Agilemania after careful evaluation. I was right. Hope this honest review helps others in line.
I have taken the session with AgileMania for PSM-1 Certification and my trainer was Piyush Rahate. Piyush's sessions are very interactive and engaging. Highly recommended!
Preeth Pandalay is an excellent trainer! He makes learning concepts easy to understand and applies them with real-world examples. His sessions are engaging and interactive. With his guidance, I successfully passed the PSM assessment on my first attempt. Thank you :)
I attended the virtual PSPO-I course offered by Agilemania, led by Sumeet Madan. The course was excellent and provided valuable insights that helped me successfully pass the exam. Additionally, the provided study materials were comprehensive and highly useful.
Sumeet was an excellent instructor. His knowledge on Scrum is excellent and he made the session interesting with his Funny but relevant examples. He also went beyond to explain how ChatGPT can be used as a tool to assist a product owner.
We will get back to you soon!
For a detailed enquiry, please write to us at connect@agilemania.com
We will get back to you soon!
For a detailed enquiry, please write to us at connect@agilemania.com