Sto utilizzando ScalaTest per testare qualche codice Scala. Io attualmente testando per le eccezioni previste con codice come questoCome testare le proprietà aggiuntive delle eccezioni attese utilizzando ScalaTest
import org.scalatest._
import org.scalatest.matchers.ShouldMatchers
class ImageComparisonTest extends FeatureSpec with ShouldMatchers{
feature("A test can throw an exception") {
scenario("when an exception is throw this is expected"){
evaluating { throw new Exception("message") } should produce [Exception]
}
}
}
Ma vorrei aggiungere ulteriore controllo sul l'eccezione, per esempio Vorrei verificare che il messaggio di eccezione contenga una determinata stringa.
C'è un modo "pulito" per farlo? O devo usare un blocco catch try?
Funziona e mi piace t la sua sintassi: è in linea con tutti i "dovrebbe essere" per i risultati delle funzioni. –
'evaluationing' è deprecato in 2.x e rimosso in 3.x. I documenti di deprecazione consigliano di usare 'an [Exception] should be throw but 'invece. Comunque 3.0.0-M14 restituisce un 'Assertion':' val ex: Assertion = an [Exception] dovrebbe essere gettatoBy {lanciare una nuova Exception ("boom")} '. C'è un modo per recuperare l'eccezione lanciata? – kostja