2010-11-09 4 views
5

En utilisant le framework boost::test, existe-t-il un moyen de détecter si une exception (d'un certain type) a été levée à partir d'une fonction?Signaler une exception dans Boost :: test

+0

double possible de [? Comment spécifier-vous qu'une exception devrait être prévu à l'aide Boost.Test] (http://stackoverflow.com/questions/172854/how-do-you-specify -that-an-exception-should-be-expected-using-boost-test) – Ferruccio

Répondre

6

Cherchez-vous à tester qu'une fonction fonctionne correctement dans certaines circonstances? Si oui

BOOST_CHECK_THROW(function(), exception_type); 

fera. Vous pouvez utiliser

BOOST_CHECK_EXCEPTION(function(), exception_type, predicate) 

appeler un prédicat arbitraire à l'exception quand il est pris et

BOOST_CHECK_NO_THROW(function()) 

pour assurer une fonction ne jette pas.

Voir: http://www.boost.org/doc/libs/1_44_0/libs/test/doc/html/utf/testing-tools/reference.html

+0

c'est ce que je cherchais. –

Questions connexes