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