1
如何在Spring控制器测试“资源”:测试弹簧控制器使用JUnit
@RequestMapping(value = "/{query}", method = RequestMethod.GET)
public @ResponseBody String getResource(
HttpServletRequest req,
HttpServletResponse res,
@PathVariable String query,
@RequestParam(value="param1", required = false) String param1,
@RequestParam(value="param2", required = false) String param2) throws SomeException{
return service.read(query);
}
而且,因为我与App Engine开发我有一个JUnit脚手架像这样:
@ContextConfiguration(locations = { "classpath:service/client-config.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
public class LocalDatastoreTest {
private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
@Before
public void setUp() {
helper.setUp();
}
@After
public void tearDown() {
helper.tearDown();
}
@Test
public void test() {
}
}
我没有使用谷歌的HTTP客户端,而不是作为RestTemplate我似乎无法让它使用App Engine – xybrek 2012-08-08 19:25:45