如何在maven中启动和停止mule
我需要在运行测试之前启动 Mule,并在测试完成后停止它。我不清楚如何改变我的 Maven pom 来实现这一点。到目前为止,我的 pom 中有以下内容:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>org.mule.MuleServer</argument>
<argument>-config</argument>
<argument>my-config.xml</argument>
</arguments>
</configuration>
</plugin>
--- 更新 ---
在下面的一些回复之后,我决定添加一些其他详细信息。
我有几个扩展 Mules FunctionTestCase 类的单元测试:
public class SomeUnitTest extends FunctionalTestCase
我开始使用 JBehave 编写一些新的客户验收测试,这些测试在 Maven“集成测试”阶段运行。如果没有 mule 实例运行,这些测试就无法成功。加载和执行故事的主类已经扩展了 JUnitStories 类:
public class MyStories extends JUnitStories
由于我无法从此类中继承FunctionalTestCase,因此我需要寻找替代方案来让 mule 在需要这些故事时运行和停止。
I need to start Mule before I run my tests, and stop it when the tests are finished. It is unclear to me how to alter my Maven pom to accomplish this. So far I have the following in my pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>org.mule.MuleServer</argument>
<argument>-config</argument>
<argument>my-config.xml</argument>
</arguments>
</configuration>
</plugin>
--- Update ---
After some replies below I decided to add some additional details.
I have several unit tests extending Mules FunctionalTestCase class:
public class SomeUnitTest extends FunctionalTestCase
I started writing some new customer acceptance tests using JBehave which are wired to run during mavens "integration-test" phase. These tests cannot succeed without an instance of mule running. The main class that loads and executes the stories already extends the JUnitStories class:
public class MyStories extends JUnitStories
Since I cannot inherit from FunctionalTestCase in this class, I need to look at alternatives to getting mule to run and stop when I need it for these stories.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不使用Mule 的FunctionalTestCase 来代替呢?它会启动内存中的 Mule 并加载您的配置。不确定启动整个独立的 Mule 会带来什么好处。
Why don't you use Mule's FunctionalTestCase instead? It fires up an in-memory Mule and loads up your configs. Not sure what you gain from starting the whole standalone Mule.
您可能可以通过利用 Maven 的阶段来完成您想要的任务。您必须定义 2 个执行。一个启动骡子,一个停止它。您可以在预测试阶段之一(可能类似于流程测试类)启动 mule,然后在测试阶段后启动 stat mule。不过,这可能非常棘手。
另一种可能性是在 junit 中启动 mule,比如在 BeforeClass 设置函数中。这可能会容易得多。看:
http://junit.sourceforge.net/javadoc/org/junit/BeforeClass.html
我要问的另一个问题是为什么你想要启动整个 mule 框架进行测试。我所在的团队就是这样做的,测试最终在构建过程中花费了大量时间,因为他们在整个测试周期中多次启动骡子(并且其他团队复制了该模式。)
You could probably accomplish what you want by leveraging maven's phases. You'd have to define 2 executions. One to start mule and one to stop it. You'd start mule in one of the pre-test phases (maybe something like process-test-classes) and then stat mule after the test phase. It could be pretty tricky, though.
Another possibility is to fire mule up in junit, somewhere like in a BeforeClass setup function. This will probably be much easier. See:
http://junit.sourceforge.net/javadoc/org/junit/BeforeClass.html
The other question I'd ask is why you'd want to fire up the whole mule framework for tests. I was on a team that did this, and tests ended up taking a tremendous amount of time during builds because they were firing up mule many times throughout the testing cycle (and other teams copied the pattern.)
尝试使用 junit @ClassRule。副作用是单个测试用例无法再执行。
Try using junit @ClassRule. The side effect is that individual test cases can not be executed any more.