2012-05-23 78 views
0

我試圖單元測試一些使用Blob存儲API的代碼,但是我得到NullPointerException此代碼:單元測試Blob存儲API

@ContextConfiguration(locations = { "classpath:service/client-config.xml" }) 
    @RunWith(SpringJUnit4ClassRunner.class) 
    public class BlobstoreDaoTest { 
     private final LocalServiceTestHelper helper = 
       new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()); 
     private final LocalBlobstoreServiceTestConfig config = 
       new LocalBlobstoreServiceTestConfig(); 

     @Autowired 
     private BlobstoreDao dao; 

     @Before 
     public void setUp() { 
      config.setUp(); 
      helper.setUp(); 
     } 

     @After 
     public void tearDown() { 
      helper.tearDown(); 
      config.tearDown(); 
     } 

     @Test 
     public void doTest() { 
     // Code omitted 
     } 
    } 

錯誤:

java.lang.NullPointerException 
    at com.google.appengine.tools.development.testing.LocalBlobstoreServiceTestConfig.setUp(LocalBlobstoreServiceTestConfig.java:52) 
+0

助手肩d包含所有的配置,並且只調用它的setUp/tearDown。本地blobstore可能沒有看到數據存儲設置,因爲它在上下文之外。 –

回答

3

你可能想要的是沿着這些線:

public class BlobstoreDaoTest { 
    private LocalServiceTestHelper helper = 
      new LocalServiceTestHelper(
       new LocalDatastoreServiceTestConfig(), 
       new LocalBlobstoreServiceTestConfig() 
      ); 

    @Before 
    public void setUp() { 
     helper.setUp(); 
    } 

    @After 
    public void tearDown() { 
     helper.tearDown(); 
    } 
...