2010-10-09 21 views
1

est-il possible d'imbriquer suivant le code de test caractéristiquescaractéristiques Scala: nid dans les déclarations

"ClassX" should { 
    "throw an IllegalArgumentException if n < 0" in { 
    ClassX(-1) must throwA[IllegalArgumentException] 
    } 
    "throw an IllegalArgumentException if n > 50" in { 
    ClassX(51) must throwA[IllegalArgumentException] 
    } 
    "throw an IllegalArgumentException if n == 35" in { 
    ClassX(35) must throwA[IllegalArgumentException] 
    } 
} 

dans un autre en déclaration comme:

"ClassX" should { 
    "throw an IllegalArgumentException if" in { 
    "n < 0" in { 
     ClassX(-1) must throwA[IllegalArgumentException] 
    } 
    "n > 50" in { 
     ClassX(51) must throwA[IllegalArgumentException] 
    } 
    "n == 35" in { 
     ClassX(35) must throwA[IllegalArgumentException] 
    } 
    } 
} 

Parce qu'il est plus facile à lire et à écrire

Répondre

0

Je préfère code comme ceci:

"My Component" >> { 
    " some general function" can { 
    "do stuff that I like" in { 
     //… 
    } 
    "do stuff others like" in { 
     //… 
    } 
    } 
} 

mais comme vous remarquerez peut-être il y a une façons gazillion de le faire.