【问题标题】:How to start activemq before your tests and move over to the tests如何在测试之前启动 activemq 并转到测试
【发布时间】:2024-04-28 21:05:01
【问题描述】:

我正在尝试测试向队列 (Activemq) 发送消息的应用程序。

我有一个 maven 测试项目,它可以从 javax.jms.MessageConsumer 消费者消费。

如果我要在 maven 构建中启动 activemq,我正在关注答案 here。但这将在它启动 activemq 时停止,并且不会将构建转移到测试执行。

我的构建 xml 部分如下所示,

        <plugin>
            <groupId>org.apache.activemq.tooling</groupId>
            <artifactId>maven-activemq-plugin</artifactId>
            <version>5.7.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <phase>process-test-classes</phase> 
                </execution>
            </executions>
        </plugin>

我正在寻找一种方法让 maven 在 activemq 启动后进入下一个阶段。

我也尝试了更新版本的插件,即activemq-maven-plugin;

        <plugin>
            <groupId>org.apache.activemq.tooling</groupId>
            <artifactId>activemq-maven-plugin</artifactId>
            <version>5.15.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <phase>process-test-classes</phase>
                </execution>
            </executions>
        </plugin>

无论哪种情况,我的 maven 构建都会停止在 ...

[INFO] --- maven-compiler-plugin:3.6.1:testCompile (default-testCompile) @ my-automation ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to C:\Users\xyz\my-automation\target\test-classes
[INFO] 
[INFO] --- maven-activemq-plugin:5.7.0:run (default) @ my-automation ---
[INFO] Loading broker configUri: broker:(tcp://localhost:61616)?useJmx=false&persistent=false
[INFO] Using Persistence Adapter: MemoryPersistenceAdapter
[INFO] Apache ActiveMQ 5.7.0 (localhost, ID:XYZ-0001:1) is starting
[INFO] Listening for connections at: tcp://127.0.0.1:61616
[INFO] Connector tcp://127.0.0.1:61616 Started
[INFO] Apache ActiveMQ 5.7.0 (localhost, ID:XYZ-0001:1) started
[INFO] For help or more information please see: http://activemq.apache.org

activemq 是从哪一点开始的。

我该如何从这一点着手?

【问题讨论】:

  • 为什么不在单元测试中使用嵌入式代理?造成这种情况的原因是什么?
  • 嗨@TimBish,是的,作为B计划,我已经开始在我的集成测试中使用嵌入式代理。请注意,这不是用于单元测试,而是用于一些集成测试。我从测试代码中得到这个的想法,只是因为 MQ 是我正在测试的应用程序的一部分,所以不想有测试代码来调出应用程序组件。

标签: maven automation activemq


【解决方案1】:

将以下内容添加到您的插件声明中:

<configuration>
    <fork>true</fork>
</configuration>

【讨论】:

    最近更新 更多