我试图从控制台应用程序使用反射运行nunit测试用例。我得到一个异常,这是我的catch块没有处理的。你能否给出一个建议如何处理调用的测试方法中的所有异常?从控制台应用程序运行nunit测试时处理异常
static void Main(string[] args)
{
// Take all classes of the current assebly to which TestFixture attribute is applied
var testClasses = Assembly.GetExecutingAssembly().GetTypes().Where(c =>
{
var attributes = c.GetCustomAttributes(typeof(TestFixtureAttribute));
return attributes.Any();
});
foreach (var testClass in testClasses)
{
var testMethods = testClass.GetMethods().Where(m =>
{
var attributes = m.GetCustomAttributes(typeof (TestAttribute));
return attributes.Any();
});
var instance = Activator.CreateInstance(testClass);
foreach (var method in testMethods)
{
try
{
Action action = (Action) Delegate.CreateDelegate(typeof (Action),
instance, method);
action();
}
catch (AggregateException ae)
{
Console.WriteLine(ae.Message);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
聚集异常发生在try块中,未被捕获。 – Salkony
什么是异常的堆栈跟踪,以及它是哪种类型,异常的消息是什么? –