有没有办法将 web @Context 引入 JUnit (CXF+Spring)

发布于 2024-09-02 11:24:36 字数 339 浏览 1 评论 0原文

我正在尝试创建单元测试环境来在我的开发环境中测试 RESTFul 服务(cfx+spring)。为了测试 RESTFul 服务,我需要在 JUnit 测试用例中使用 @Context。 @Context 应包含 HttpRequest、HttpSession、ServletContext、ServletConfig 和所有其他与 Web 服务器相关的信息。

我已经为上述设置了 JUnit,但是当我运行时,@Context 为 null。这可能是因为没有运行网络服务器并且没有@Context。我只是怀疑是否有办法创建示例 web @Context 并传递给 JUnit。欢迎任何其他想法将 web @Context 引入 JUnit 测试用例。

I am trying to create unit test environment to test RESTFul services (cfx+spring) in my dev environemnt. To test RESTFul Services, I require @Context within JUnit test cases. @Context should contain HttpRequest, HttpSession, ServletContext, ServletConfig and all other webserver related information.

I have setup the JUnit for the above, but when I run, @Context is coming as null. This could be because there is no webserver running and there is no @Context. I am just doubting whether there is a way to created sample web @Context and pass to JUnit. Any other ideas are welcome to bring web @Context into JUnit test cases.

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

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

发布评论

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

评论(2

清秋悲枫 2024-09-09 11:24:36

您需要嵌入一个 Web 容器。

尝试将 Jetty 作为嵌入式容器。

这篇文章包含有用的信息。

You need to embed a web container.

Try for example Jetty as an embedded container.

This article contains useful information.

宫墨修音 2024-09-09 11:24:36

Spring 对模拟 Web 服务器环境有一些帮助,因此无需真正的 Web 容器即可进行测试。请参阅这些 Spring Framework 有关测试的文档开始使用。我没有在您的上下文中使用过这个,但它可能会有所帮助。

Spring has some help for mocking the web server environment and thus testing without a real web container. See these Spring Framework docs on testing to get started. I haven't used this in your context, but it may be helpful.

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