TestNG单元测试在maven安装,安装->部署到jetty->启动jetty->运行测试->停止服务器
我有一个 Maven 项目。
我想测试(spring)控制器类,并且还编写了一个测试类。为了成功运行这个测试类,我希望将Web应用程序部署在(jetty)服务器中。
当我执行 maven clean install.project 时,我如何实现这一目标是
built->deployed to server->start server->run test->stop server
我一直在查看jetty插件和cargo插件,但仍然发现很难做我想做的事情。
I have a maven project.
I want to test (spring) controller class and also wrote a test class.To successfully run this test class,I want the web app to be deployed in the (jetty )server.
How I can achieve this, when I execute maven clean install.project is
built->deployed to server->start server->run test->stop server
I have been looking at jetty plugin and cargo plugin but still finding it difficult to do what I want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

如果您想对 Spring 控制器进行单元测试,则无需将 Web 应用程序部署到 jetty。 Spring 框架具有文档中的测试支持 这里。
网络上有很多例子。您还可以参考测试类 这里使用了testNG。
如果您确实想在 jetty 中运行测试,请参阅这些说明 。本质上,您可以将码头的启动和停止绑定到
pre-integration-test
和post-integration-test
阶段。If you want to unit test your spring controllers, you do not need to have your web application deployed to jetty. Spring framework has testing support as documented here.
There are many examples in the web. You can also refer to the test classes here which uses testNG.
If you do want to run tests in jetty, then refer to these instructions. Essentially you would bind the jetty start and stop to
pre-integration-test
andpost-integration-test
phases.