Note that there are some explanatory texts on larger screens.

plurals
  1. POJUnit Test of Code that uses GAE/J URLFetchServiceFactory.getURLFetchService()
    primarykey
    data
    text
    <p>I've got some code I'm deploying to Google App Engine - Java (GAE/J) that makes use of the <code>URLFetchService</code>. I'd like to use JUnit to test this code. Per the <a href="http://code.google.com/appengine/docs/java/tools/localunittesting.html#Introducing_App_Engine_Utilities" rel="nofollow">testing documentation,</a> it appears I should have a test that uses their <code>LocalURLFetchServiceTestConfig</code> class ROUGHLY as follows:</p> <pre><code>public class MyRemoteServiceTests { private static final LocalURLFetchServiceTestConfig urlConfig = new LocalURLFetchServiceTestConfig(); private static final LocalServiceTestHelper helper = new LocalServiceTestHelper(urlConfig); @Before public void setUp() throws Exception { service = new SampleService(); helper.setUp(); } @After public void tearDown() throws Exception { service = null; helper.tearDown(); } @Test public void testThatCallsCodeThatUsesUrlFetch() { Object data = service.getRemoteDataUsingUrlFetch("foo", "bar"); Assert.assertNotNull(data); } } </code></pre> <p>I'm finding that this test continues to fail despite using the "helper" as suggested in the GAE/J documentation on testing: "<code>The API package 'urlfetch' or call 'Fetch()' was not found.</code>".</p> <p>I was assuming that using the "helper" would somehow setup the GAE environment such that when I call <code>URLFetchServiceFactory.getURLFetchService()</code> from within my <code>getRemoteDataUsingUrlFetch</code> method, the interface returned would be an instance of <code>LocalURLFetchService</code> that would just "work" but that seems NOT to be the case. </p> <ul> <li>How can I test this code? </li> <li>Am I missing something? (I'm pretty new to GAE...) </li> <li>Do I have to refactor my <code>getRemoteDataUsingUrlFetch</code> so that it doesn't use <code>URLFetchServiceFactory.getURLFetchService()</code> because that makes it untestable locally??? (That sounds like it would really suck...)</li> </ul> <p>Any help/suggestions much appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload