An warware: gwajin tsarin sarrafawa

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&#91;i&#93; >= 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.

Shafi posts:

Leave a Comment