Como faço para usar ExpectedException em testes de C ++ / CLI NUnit?
-
12-09-2019 - |
Pergunta
Como você faz o equivalente a:
[Test, ExpectedException( typeof(ArgumentOutOfRangeException) )]
void Test_Something_That_Throws_Exception()
{
throw gcnew ArgumentOutOfRangeException("Some more detail");
}
... em C ++ (o exemplo há C #)? Tanto quanto eu posso ver, não há nenhuma função typeof () para o C ++ implementação de NUnit.
Solução
Para evitar qualquer outro caça ao redor para idades tentando encontrá-lo, aqui está a solução:
[Test, ExpectedException( ArgumentOutOfRangeException::typeid )]
void Test_Something_That_Throws_Exception()
{
throw gcnew ArgumentOutOfRangeException("Some more detail");
}
Basta usar o ::typeid
da exceção: -)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow