Apache Camel:如何使用CamelTestSupport在单元测试时打印异常跟踪

时间:2015-02-13 20:38:39

标签: unit-testing exception-handling apache-camel integration testng

使用Camel-core v2.14.1和camel-testng v2.14.1

尝试单元测试基本路线。

RouteBuilder类名为FileToJmsRB,路由以这种方式配置

@Override
public void configure() {
     from("file:C:\\camel_folder\\orders")
       .when(fileToJmsConditions.camelFileNameEndingWithXml(this))
            .to("file:C:\\camel_folder\\recieved")
}

fileToJmsConditions是一个我无法作为Spring Bean注入的变量。

My Test类扩展了CamelTestSupport,它覆盖了createRouteBuilder(),如下所示

@Override
protected RouteBuilder createRouteBuilder() throws Exception{
    return new FileToJmsRB();
}

我将方法配置为测试。

@Test
public void testTextFileMove() throws Exception{
    template.sendBodyAndHeader("file:C:\\camel_folder\\orders"
        , "Hello World"
        , Exchange.FILE_NAME
        , "hello.txt");

    Thread.sleep(10000);

    File target = new File("C:\\camel_folder\\recieved\\hello.txt");
    assertTrue(target.exists(), "File Not Moved");
}

正在运行

maven install

在项目中,我希望在控制台中使用StackTrace进行空指针异常。

然而,观察没有提示Exception Thrown的类型,也没有打印出stacktrace。它只是表示测试失败但不打印异常类型或堆栈跟踪。

 Tests run: 2, Failures: 1, Errors: 0, Skipped: 1

但是,如果我将我的configure方法包装在FileToJmsRB类中     试着抓... 只有这样我才会看到抛出的NullPointerException和打印的堆栈跟踪。

没有其他更优雅的方式更优雅地处理这个问题吗?因为这样我必须在每个Route Builder类中尝试... catch ...?

0 个答案:

没有答案