Unit testing is the practice of writing code to test your code and then run those tests in an automated fashion. ✅
🔹🔸🔹🔸
Here is an example. 👨🏻💻
Imagine you have this function somewhere in your code.
It’s a basic calculate function that takes an input and depending on some conditions, it returns different values.
public float CalculateTax(int input)
{
if (x) return ...;
if (y) return ...;
return ...;
}
If you want to test this function manually :
1️⃣ You have to run your application
2️⃣ Perhaps you have to login
3️⃣ Maybe do a few clicks here
4️⃣ There to get to a page where this function is used.
5️⃣ You have to fill out a form
6️⃣ Submit it
7️⃣ Verify if this function returned the right result.
And then you have to repeat all these steps, each time using different values in your form. 🤦🏻♂️
🔸🔹🔸🔹
Manual testing is expensive 💸
As you can see, this is very time-consuming. ⌛️
This workflow to test this function may take several minutes every time❗️
Now to make matters worse, this is not the only function in your application. 🌍
In a real application, you have tens or hundreds of functions like this ❗️
As your application grows in size and complexity, the time required to manually test all the different bits and pieces increases exponentially. ⏱
So, that’s why we use Automated Testing. ♻️
🔺🔹🔺🔹
https://t.me/pgimg/24
[ Full Article ] : http://bit.do/utdd
〰〰〰〰〰〰
#CleanCode #UnitTest #TDD
@ProgrammingTip