Gwajin tsarin sarrafawa muhimmin al'amari ne da ke da hannu cikin haษaka software da shirye-shirye, musamman lokacin aiki tare da babban saiti na Javascript, kamar yaren TypeScript. Ana iya rarraba tsarin sarrafawa gabaษaya zuwa jeri, zaษi da maimaitawa, kowanne yana da tasiri daban-daban akan kwararar shirin kuma saboda haka yana ษaukar tasiri mai mahimmanci don gano kwaro ko kuskure.
Tsarin sarrafawa yana jagorantar odar aiwatar da lambar shirin. Wahalar ta ta'allaka ne a cikin sarฦaฦฦiyar waษannan sifofi tun da kuskure a cikin tsarin sarrafawa na iya haifar da munanan matsalolin shirin.
A cikin TypeScript, gano kuskure a cikin tsarin sarrafawa yana buฦatar gwaji na tsari. Wannan ya cika ta saita tushen gwaji, gwajin reshe da kuma gwajin yanayi.
Saita Bisa Gwajin
An ayyana shi azaman tsari inda aka samo shari'o'in gwaji daga yankin fitarwa na shirin, saita tushen gwaji muhimmin bangare ne na shirye-shiryen TypeScript.
function setBasedTesting(value: number): number { let resultValue: number; if (value > 10) { resultValue = value * 10; } else { resultValue = value * -1; } return resultValue; }
A cikin wannan misali mai sauฦi, muna ayyana aikin da ke karษar lamba a matsayin hujja, to, dangane da ฦimar wannan lambar, yanayin yana aiwatar ko dai ta hanya ษaya ko wata. Ana buฦatar rubuta gwaje-gwaje don rufe abubuwa biyun (lamba ya fi 10 girma kuma lambar ta gaza ko daidai da 10).
Gwajin reshe
A cikin TypeScript, ana amfani da gwajin reshe don gwada kowane reshe na tsarin sarrafawa kamar madaukai ko bayanan sharadi.
function branchTesting(array: number[]): number[] { let resultArray = []; for (let i = 0; i < array.length; i++) { if (array[i] >= 0) { resultArray.push(array[i] * 2); } else { resultArray.push(array[i]); } } return resultArray; }
Wannan aikin zai bi ta kowane nau'i a cikin tsararru, kuma dangane da ko sinadarin yana da inganci ko a'a, zai aiwatar da rassa daban-daban. Cikakken gwaji zai rufe saitin bayanan gwaji inda akwai abubuwa masu kyau da mara kyau a cikin tsararrun, gami da harka-gefen tsararrun fanko.
Gwajin yanayi
Ana aiwatar da gwajin yanayi don gwada rassan da ke sarrafa yanayin. Ya kamata a tsara gwaje-gwaje ta hanyar da a cikin rassan da ke sarrafa yanayin da yawa, kowane yanayi yana aiwatar da shari'o'in gaskiya da na ฦarya. Daidaitaccen rarrabuwar kawuna da nazarin ฦimar iyaka na iya taimakawa wajen ฦirฦirar shari'o'in gwaji masu inganci.
function conditionTesting(value: number, flag: boolean): number { let result: number; if (flag) { result = value * 2; } else if (!flag && value > 10) { result = value * 3; } else { result = value; } return result; }
A wannan yanayin, akwai yanayi da yawa da ke sarrafa rassan - gaskiyar tuta da ฦimar ฦima. Madaidaicin gwaji zai buฦaci masu ฦira don gwada kowane yanayi daban-daban kuma mafi kyau duka haษaษษun yanayi.
Fahimta da aiwatar da ayyukan gwajin tsarin sarrafawa a cikin Typescript na iya haษaka daidaito da amincin lambar tushe, ta haka yana haษaka ingancin software gabaษaya.