运行 junit 作为服务器并注入更改?
出于某些测试目的,如果每次测试运行都不必重新启动我的码头服务器,那就太好了。
使用 jrebel,我可以直接应用源更改。
是否可以以一种可以动态注入更改然后重新运行测试而无需重新启动服务器的方式运行我的码头服务器?
for some testing purposes it would be great not having to restart my jetty server for every test run.
With jrebel i can apply source changes directly.
Is it possible to run my jetty server in a way that i could inject changes dynamically and then rerun the tests without having to restart the server?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于您想要注入的更改类型。
也就是说,我相信这里有一个更深层次的问题。从测试质量的角度来看,重新启动 Jetty 是正确的做法。它确保每个测试都从干净的页面开始,从而最大限度地减少测试间依赖的风险。另一方面,这是昂贵的(时间方面)并且会使您的套件运行速度变慢。
如果我是您,我会按如下方式解决这个问题:我将重构我想要测试的代码(大概是 servlet),以便它们不依赖于 Jetty 基础设施,并且可以独立运行。例如,如果我有一个 servlet 类
SomeServlet
及其doGet()
方法,我将重构它,使其实现MyServelt
,其>goGet()
采用MyRequest
、MyResponse
参数。完成此操作后,您就可以在没有 Jetty 服务器的情况下对
MyServlet
进行单元测试。这不仅可以让您更快地进行测试,还可以简化调试会话并使您的组件更加解耦。当然,您需要添加一些管道代码:一个将Servelt接口适配为MyServelt对象的类(通过委托)。It depends on the kind of changes that you want to inject.
That said, I believe there is a deeper issue here. Restarting Jetty is the right thing to do from a test-quality standpoint. It ensures that each test starts from a clean page thereby minimizing the risk of inter-test dependencies. On the other hand, this is costly (time-wise) and make your suite runs slower.
If I were you, I would address this as follows: I will refactor the code that I want to test (presumably: servlets) such that they do not depend on the Jetty infrastructure, and can run stand-alone. For instance, If I have a servlet class
SomeServlet
with itsdoGet()
method, I will refactor it such that it implementMyServelt
whosegoGet()
takes aMyRequest
,MyResponse
parameters.Once you do that, you can unit-test
MyServlet
without a Jetty server. This will allow you not only to test faster, but also ease your debugging sessions and make your components more decoupled. Of course, you will need to add some plumbing code: a class that adapts the servelt interface to a MyServelt object (via delegation).