الگوی arrange , act , assert در نوشتن تست های واحد به یکی از استاندارد ها در صنعت تبدیل شده که باعث میشه تست های واحد ما تمیز تر و خوانا تر بشن
این الگو به شما پیشنهاد میده که متد تست خودتون رو به سه بخش تقسیم کنین و هر بخش مسئولیت خودش رو بر عهده داره 💡
قسمت اول arrange فقط شامل کد هایی میشه که شما برای تست نیاز دارین (راه اندازی تست)
در این قسمت اشیا و یا ماک ها در صورت نیاز ایجاد میشن و مقادیری که به عنوان خروجی انتظار داریم تعریف میشن
در قسمت arrange معمولا استاندارده که بیایم یک متغیر به اسم sut تعریف کنیم (system under test) و به عنوان مقدار به این متغیر ، متدی که میخوایم تست کنیم رو بهش پاس بدیم 🤖
در قسمت act متدی که میخوایم تست کنیم رو صدا میزنیم (sut) و بهش ورودی تست خودمون رو میدیم پس این مرحله میشه فراخوانی متدی که قراره مورد تست قرار بگیره
در قسمت assert هم چک می کنیم که آیا خروجی مرحله act که میشه (actual value) با مقدار مورد انتظار ما که در مرحله arrange تعریف شد (expected value) مطابقت داره یا نه 🕵♂️
#jest
#unit_test
#software
#typescript
#AAA_pattern
ترجمه:
AAA rule in writing unit test: 🧪
The arrange, act, assert pattern in writing unit tests has become one of the standards in the industry, which makes our unit tests cleaner and more readable.
This template suggests you to divide your test method into three parts and each part has its own responsibility.
The first part of arrange contains only the codes you need for testing (starting the test).
In this section, objects or mocks are created if needed and the values we expect as output are defined
In the arrange section, it is usually standard to define a variable named sut (system under test) and pass the method we want to test as the value to this variable.
In the act part, we call the method we want to test (sut) and give it our own test input, so this step can call the method that is going to be tested.
In the assert section, we also check whether the output of the act step (actual value) corresponds to our expected value defined in the arrange step (expected value) or not 🕵♂️
#jest
#unit_test
#software
#typescript
#AAA_pattern
The arrange, act, assert pattern in writing unit tests has become one of the standards in the industry, which makes our unit tests cleaner and more readable.
This template suggests you to divide your test method into three parts and each part has its own responsibility.
The first part of arrange contains only the codes you need for testing (starting the test).
In this section, objects or mocks are created if needed and the values we expect as output are defined
In the arrange section, it is usually standard to define a variable named sut (system under test) and pass the method we want to test as the value to this variable.
In the act part, we call the method we want to test (sut) and give it our own test input, so this step can call the method that is going to be tested.
In the assert section, we also check whether the output of the act step (actual value) corresponds to our expected value defined in the arrange step (expected value) or not 🕵♂️
#jest
#unit_test
#software
#typescript
#AAA_pattern