Testing with app engine in Java
Posted on
by Charalampos Chrysikopoulos
I wanted to make a template for my tests in a web app using spring and google app engine. The test uses of course JUnit and annotations. Here is the result:
@ContextConfiguration(locations = {"classpath:test-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class TheTest {
@Before
public void setUp() throws Exception {
ApiProxy.setEnvironmentForCurrentThread(new TestEnvironment());
ApiProxy.setDelegate(new ApiProxyLocalImpl(new File(".")) {
});
}
@After
public void tearDown() throws Exception {
ApiProxy.setDelegate(null);
ApiProxy.setEnvironmentForCurrentThread(null);
}
@Autowired
private ToBeTestedRepository toBeTestedRepository ;
@Test
public void testLottoFileReader() {
// Do some tests here using the toBeTestedRepository
}
public void setToBeTestedRepository (ToBeTestedRepository toBeTestedRepository ){
return this.toBeTestedRepository = toBeTestedRepository;
}
public ToBeTestedRepository getToBeTestedRepository () {
return toBeTestedRepository;
}
The methods setUp() and tearDown() tell the datastore that we are using it localy.