According to this example, it goes in the same package as the controller it tests.
Why is that necesssary?
I think it would be tidier to have all of my unit tests in a testing
package - would there be a problem with doing so?
package com.example.web.controllers;
...imports...
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/testApplicationContext.xml"})
public class HomeControllerSysTest extends AbstractJUnit4SpringContextTests {
private static final Logger log = Logger.getLogger(
HomeControllerSysTest.class.getName());
private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
@Before
public void setUp() {
helper.setUp();
}
@After
public void tearDown() {
helper.tearDown();
}
@Test
public void testHomeController() throws IOException {
final String url = "http://localhost:8080/movie/test";
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage(url);
assertEquals("The Page Title", page.getTitleText());
// there are many different methods to query everything on your
// page. Please refer to the HttpUnit homepage
HtmlElement header = page.getElementsByTagName("h1").get(0);
assertNotNull(header);
String headerValue = header.getNodeValue();
assertEquals(headerValue, "Hello World!");
}
}