[英]How to cover branches in unit testing
我有此功能需要進行單元測試,
我寫了一些規范,可以正常工作。 但是在代碼覆蓋率中,它表示if (text !== '') {}
Else path not taken
在該行Else path not taken
。
我不確定如何在函數內部測試變量。
以下是我寫的一些規格。
it('should split the content correctly', inject([GenerateInlineTagsService], (service: GenerateInlineTagsService) => {
const obj = service.getView(RANGES);
expect(JSON.stringify(obj)).toEqual(JSON.stringify(inlineSplitContent));
}));
創建一個新的測試用例,並在測試時將低於值的值傳遞給您的函數,以便進行else
分支:
const content = { inlineEntityRanges: [], text: '' }
同樣,在測量分支覆蓋范圍時,如果可能的else
,將每個if
塊寫入else
塊,這是必需的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.