Tabbas, ga tsarin labarin.
Testing wani bangare ne na kowane software ci gaba tsari. Wannan shine yadda zaku tabbatar da cewa code Ka rubuta yana yin abin da aka yi niyya don yi da kuma yadda kake kama duk wani kwari da ƙila ya zame a ciki. Hanya ɗaya ta gama gari ta ba da rahoto kan adadin lambar ku ta gwajin gwajin ku ita ce ta rahotannin ɗaukar hoto. A cikin JavaScript, sanannen tsarin gwaji wanda ke ba da ayyuka don samar da rahotannin ɗaukar hoto shine karimcin. Gudun 'gwaji: ɗaukar hoto' umarni a cikin Jest zai ba da cikakken kewayon gwaji.
npm test -- --coverage
Fahimtar Rahoton Rahoton Jest
Bayan gudanar da umarnin 'gwaji: ɗaukar hoto', Jest yana samar da cikakken rahoton ɗaukar hoto. Wannan rahoto ya ƙunshi nau'i-nau'i da yawa - Jawabin, Branches, ayyuka, Da kuma Lines.
Takaitaccen bayanin wadannan nau'ikan shine kamar haka -
- Bayani: Wannan yana bayyana jimlar adadin maganganun da ke cikin rubutun ku, tare da adadin adadin maganganun da gwaje-gwaje suka rufe.
- Rassan: Wannan yana ƙayyadaddun adadin wuraren yanke shawara (misali, idan bayanai) a cikin rubutun ku, tare da adadin waɗanda gwaje-gwajen ke rufewa.
- ayyuka: Wannan yana nufin jimlar adadin ayyuka, yana nuna adadin ayyukan da gwaje-gwaje ke rufewa.
- Layuka: Wannan yana nuna adadin layukan layukan da za a iya aiwatarwa a cikin rubutun ku, kuma yana nuna adadin waɗanda gwaje-gwaje ke rufe.
Matakai Don Samar da Rahoton Rubutun Jest
Anan akwai jagorar mataki-mataki don samar da rahoton ɗaukar hoto ta amfani da Jest -
1. Sanya Jest idan ba a riga an yi haka ta amfani da npm ko yarn:
npm install --save-dev jest
2. Ƙara rubutun gwaji a cikin kunshin ku.json fayil. Misali kamar haka:
{ "scripts": { "test": "jest" } }
3. Yanzu, zaku iya gudanar da gwaje-gwajenku cikin sauƙi tare da ɗaukar hoto kamar haka:
npm test -- --coverage
Wannan umarnin zai samar da rahoton ɗaukar hoto a cikin tashar ku da kuma ƙarin cikakken rahoton HTML a cikin kundin jagora a tushen aikin ku.
Amfanin Amfani da Jest don Rufin Gwaji
karimcin kayan aiki ne mai ƙarfi don gudanar da gwaje-gwaje kuma yana da babban fasali don lambar ɗaukar hoto. Amfani karimcin bayar da rahoton ɗaukar hoto yana tabbatar da cewa kuna rubuta gwaje-gwajen da ke da tasiri wajen gwada aikin lambar ku, zai iya tabbatar da amfani yayin ƙoƙarin nemo sassan software ɗinku da ba a gwada su ba. Har ila yau, Jest yana ba da yanayin "watch", yana sake yin gwajin ku ta atomatik lokacin da ya gano canji a fayilolinku.
Ka tuna, yayin da babban gwajin ɗaukar hoto na iya zama babban buri, yana da mahimmanci a rubuta gwaje-gwaje masu ma'ana kuma kada a rataye kan cimma ɗaukar hoto 100%. Yana da matukar daraja a sami ƙaramin kaso na kyakkyawan tunani, ingantattun gwaje-gwaje fiye da kaso mafi girma na gwaje-gwaje marasa inganci. Gwaji game da inganci ne, ba adadi ba.
Kammalawa
A ƙarshe, Jest yana ba da cikakkiyar fasali, kayan aikin ɗaukar hoto mai sauƙin amfani wanda aka gina a cikin tsarin gwaji da kansa. Tare da wannan kayan aiki, masu haɓakawa za su iya yin nazari cikin ƙarfin gwiwa game da tasirin rukunin gwajin su, gano wuraren da ba su da ɗaukar hoto kuma tabbatar da cewa an lissafta duk lamuran gaba. Ana iya yin gyare-gyare, gyarawa, ko ƙara sabbin abubuwa zuwa ga codebase tare da kwanciyar hankali, sanin cewa duk wani canje-canjen da ke karyawa za a iya kama shi da sauri ta wurin gwaji.