2014-01-07 40 views

回答

12

它的意思是「它」,就像在「它」一樣。正如在測試聲明中讀起來像一個句子。你describe由什麼it做的一個對象。就那麼簡單。

例如:

保齡球球是圓的

保齡球球有3個孔

可能轉換到測試的層次結構是這樣的:

Bowling Ball 
    it is round 
    it has three holes 

哪會轉換到以下測試設置:

describe(BowlingBall, function() { 
    it('is round', function() {}); 
    it('has three holes', function() {}); 
}); 

因此,因爲它讀得很好,它就成爲您分離單個測試用例的方式。它還鼓勵您以一致的方式編寫測試描述,因爲it是描述測試的句子的一部分,這使得您的測試套件在長期內更具可讀性。

最後BDD是所有關於測試作家的可讀性。所以這只是糖。

0

沒有那樣的。 :)

這是一個塊使您的規格更具可讀性。特別是,你可以寫這樣的東西:

describe("When the user clicks the button", function() { 
    it("renders the div with class .hello", function() { 
     // your assertion here 
    }); 
}); 

所以你在控制檯測試輸出看起來像:

When the user clicks the button renders the div with class .hello