单元测试maven插件 [英] unit-testing maven plugins

查看:183
本文介绍了单元测试maven插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找有关如何为Maven插件编写单元测试的信息。虽然Maven网站上有关于此主题的页面,但只有一个示例单元测试,没有任何用处。我还找到了这个wiki页面,但它还没有已经更新超过4年,所以我不愿意投入任何信任。

I'm looking for information about how to write unit tests for Maven plugins. Although there's a page on the Maven site about this topic, there's only one example unit test, which does nothing useful. I also found this wiki page, but it hasn't been updated for more than 4 years, so I'm reluctant to invest any faith in it.

我查了一本书Maven的权威指南,但它没有甚至没有提到这个话题。我想用Groovy或Java编写单元测试,并希望了解有关如何执行此操作的任何信息。

I checked the book "The Definitive Guide to Maven", but it doesn't even mention the subject. I'd like to write my unit tests in either Groovy or Java, and would appreciate any information about how to do this.

我正在使用Maven版本2.1.0 。

I'm using Maven version 2.1.0.

推荐答案

您发布的第一个链接是了解各种可能性的正确位置从...开始。但举例来说,最好的办法是查看现有插件的来源。话虽如此:

The first link you posted is the right place to learn about the various possibilities and to start with. But for examples, the best thing to do would be to look at the sources of existing plugins. Having that said:

对于单元测试,我的偏好是 maven-plugin-testing-harness 。您可以在 Maven Plugin Harness Wiki <中学到更多相关信息。 / a>但是,正如我所说,特别是在使用它的插件中,例如 maven-compiler-plugin 。检查 CompilerMojoTestCase

For unit testing, my preference goes to the maven-plugin-testing-harness. You can learn (a bit) more about it in the Maven Plugin Harness Wiki but, as I said, especially in plugins using it, for example the maven-compiler-plugin. Check the CompilerMojoTestCase.

For 集成测试(IMO对于插件进行集成测试非常重要),我建议 shitty-maven-plugin (超级有用的集成测试ThingY),特别是如果您对在Groovy中编写测试感兴趣,或者行家-调用-插件。它们相似但具有另一个不具备的两个特征。 SHITTY插件的网站提到了几个使用它的插件。看看吧。

For integration testing (it's IMO very important for plugins to do integration testing), I'd recommend the shitty-maven-plugin (Super Helpful Integration Testing ThingY), especially if you are interested by writing tests in Groovy, or the maven-invoker-plugin. They are similar but have both features that the other doesn't. The website of the SHITTY plugin mentions several plugins using it. Check it out.

这篇关于单元测试maven插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆