0

我经常需要在我的 devKit 连接器中等待一些异步进程完成(然后导致 isConnected 返回 true )

@ValidateConnection
public boolean isConnected() {
    return isConnected;
}

我怎样才能让我的功能单元测试等到完成。我原以为单元测试会等到我的流程中的所有连接器都“连接”起来。

Atm 我在单元测试中使用睡眠来解决我的 FunctionalTestCase

Thread.sleep(5000);

assertEquals(1, targetEngineApplication.getNumberOfMessagesReveived());

编辑_ _ __ _ __ _ __ _ __ _ __ _ ____

连接代码:

@Connect
public void connectMethod(final String configFileLocation) throws ConnectionException {

    System.out.println("Connect called with config:" + configFileLocation);
    try {
        Engine.doInitialise(configFileLocation);
        Engine.doStart();
    } catch (InitialisationException e) {
        throw new ConnectionException(ConnectionExceptionCode.UNKNOWN, "0", e.getCause().getMessage(), e);
    } catch (StartingException e) {
        throw new ConnectionException(ConnectionExceptionCode.UNKNOWN, "0", e.getCause().getMessage(), e);
    }
    // this will also tell the unit tests to start
    isConnected = true;
}
4

1 回答 1

2

是这样的:当功能测试开始时,所有需要初始化和启动的都是。

DevKit 连接器的“连接”概念是不同的:当使用消息处理器时,连接会按需发生。

那么您想在测试中等待什么:连接器的初始化序列已经完成,或者特定的处理器方法已经执行?

作为记录,Mule in Action的第 12 章涵盖了允许处理异步场景的测试技术。

于 2013-07-05T16:07:34.760 回答