我正试图在泽西岛进行单元测试。
不直接依赖 Jersey 的类可以使用标准 JUnit 进行单元测试。这个还行。
但是也有 Jersey(或者,我应该说 JAX-RS?)依赖类。为了测试这些(包括注释的正确性、序列化、状态码等),Jersey 提供了包含基JerseyTest
类的“测试框架”。
这也很好,可以理解。
然后,然而,官方文档指定了几种类型的支持的容器,其中的子类JerseyTest
可以执行。
这些容器似乎可以分为两种类型:
- 真正的容器
- 内存容器
从我目前(新手)的角度来看,所有类型 #1 的容器都提供相同的功能。因此,让我们以灰熊作为第一类代表。
现在,很明显内存容器(根本不是真正的容器)比 Grizzly 快。因此,我想使用这个容器来测试 Jersey 依赖类。但是官方文档中的这个声明让我感到困惑:
此容器不支持 servlet 和其他容器相关功能,但它是简单单元测试的完美选择。
我试图用谷歌搜索内存容器与 Grizzly 的比较,但没有找到任何明确的比较。我也阅读了这个高度技术性的线程,但我仍然不清楚内存容器的缺点。
在这方面,我有两个问题:
- 什么是“servlet 和其他依赖容器的特性”(不需要一个全面的列表,只是一般性的描述)?
- 如果我选择内存容器,我是否会遇到代码通过测试但在生产中失败的情况(如果这很重要,我将在生产中使用 Tomcat)?
谢谢