Maven 插件测试入门

发布于 2024-09-10 01:50:25 字数 385 浏览 2 评论 0原文

我正在编写一个非常简单的 Maven 插件,但我对测试部分有点迷失。基于插件开发人员站点,有几种不同的工具可以实现同样的事情,文档似乎已经过时了...我找到了诸如 也是如此,并查看了“核心”插件,但这对我来说仍然很不清楚。

由于似乎没有一个解决方案,因此我在此询问您的个人经验。

I'm writing a very simple Maven plugin, and I am kind of lost with the testing part. Based on the plugin developers site, there are several different tools to achieve the same things, which documentation seem outdated... I found resources like this too, and took a look at the "core" plugins, but this is still very unclear to me.

As there does not seem to be one solution for this, I am asking for your personal experience here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剩余の解释 2024-09-17 01:50:25

我没有太多要添加到 插件测试回顾策略页面非常详尽,它实际上取决于您想要编写的测试类型。

但由于您要求实际反馈,我的建议是编写单元测试和集成测试,后者在插件时非常重要(如果您想跳过某些内容,请不要跳过集成测试)。

对于单元测试,请使用 maven -插件测试线束。检查 Maven Plugin Harness Wiki 和现有插件(例如 maven) -compiler-plugin (请参阅 CompilerMojoTestCase)。

对于集成测试,我建议使用 maven- invoker-plugin 和/或 shitty-maven-plugin。它们很相似,但仍然存在细微差别,因此您可能会根据情况更喜欢其中一种。请参阅矩阵了解详情。

另请参阅

I don't have much to add to the Review of Plugin Testing Strategies page which is pretty exhaustive and it really depends on the kind of tests you want to write.

But since you're asking for practical feedback my recommendation would be to write both unit tests and integration tests, the later being extremely important when plugins (if you want to skip something, don't skip integration tests).

For Unit Tests, use the maven-plugin-testing-harness. check the Maven Plugin Harness Wiki and existing plugins like the maven-compiler-plugin (see the CompilerMojoTestCase).

For integration tests, I suggest to use the maven-invoker-plugin and/or the shitty-maven-plugin. They're similar but still have slight differences so you might prefer one over the other depending on the situation. Refer to the matrix for the details.

See also

蓝眼睛不忧郁 2024-09-17 01:50:25

采纳 Perl 的建议 - 总是有不止一种方法可以做到这一点

这实际上取决于您的测试范围。如果您只是简单地测试逻辑,那么基本的 JUnit 测试用例就可以了;如果您正在执行模拟测试或需要某些上下文的集成测试,并且您只是不想重做人们所做的事情,那么 Maven 页面已经解释了如何应用这些不同的技术。

Take the Perl's advice - there's always more than one way to do it.

It really depends on the scope of your test. If you are testing against simply just the logic, a basic JUnit test case will do; If you are performing mock tests or integration tests with some contexts needed and you simply do not want to redo what people have done, the Maven's page has explained how these different techniques shall be applied.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文