为JERSEY Web服务编写测试用例的最佳方法是什么? [英] What is the best way to write a test case for JERSEY web services?

查看:130
本文介绍了为JERSEY Web服务编写测试用例的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Jersey库实现的JAX-RS Web服务,现在我想测试它。为了做到这一点,我想在我的测试中通过使用模拟服务预初始化来托管此服务。

I have a JAX-RS web service implemented with Jersey library and now I want to test it. In order to do that I'd like to host this service in my test by preinitializing it with mocked services.

托管此类服务和执行的最佳方式是什么测试电话?

What is the best way to host such a service and execute the test calls?

@Path("/srv")
public class MyService
{
   @GET
   public void action(@Context UriInfo uri)
   { ... }
}

@Test
public void myTest()
{
   MyService service = new MyService();
   service.setSomething(...);

   // How do I host it?

   // How do I call it?
}


推荐答案

新的(修订的)泽西岛测试框架是Jersey 1.1.2-ea版本的一部分,现在支持进程内或内存中测试。要在内存中运行测试,您只需将属性 test.containerFactory 设置为 com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory ,即按如下方式运行测试:


mvn clean test -Dtest.containerFactory = com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory -DenableLogging

The new (revised) Jersey Test Framework which is part of the Jersey 1.1.2-ea release now supports the In-Process or In-Memory testing. In order to run your tests in-memory all you have to do is set the property test.containerFactory to com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory, i.e., run your tests as follows:

mvn clean test -Dtest.containerFactory=com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory -DenableLogging

有关详情,请浏览泽西测试框架重新访问的博客条目 http: //blogs.oracle.com/naresh

For more details please go through the blog entry titled Jersey Test Framework re-visited! at http://blogs.oracle.com/naresh.

这篇关于为JERSEY Web服务编写测试用例的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆