2013-05-12 74 views
1


我想模擬編寫單元測試的gae用戶服務,並且無法獲得以下代碼來工作。無法模擬GAE用戶服務

我的測試課程如下。

public class AuthenticationTest { 

    private final LocalServiceTestHelper helper = 
     new LocalServiceTestHelper(new LocalUserServiceTestConfig()) 
      .setEnvIsAdmin(true).setEnvIsLoggedIn(true) 
      .setEnvEmail("[email protected]"); 

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

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

    @Test 
    public void testIsAdmin() { 
     UserService userService = UserServiceFactory.getUserService(); 
     assertTrue(userService.isUserAdmin()); 

     String email = userService.getCurrentUser().getEmail(); 
     assertEquals(email, "[email protected]"); 
    } 
} 

我發現userService.getCurrentUser()總是返回null。

大部分代碼取自developers.google.com中的示例。我添加的唯一的東西是呼叫.setEnvEmail(「[email protected]」)

任何幫助,將不勝感激。

感謝,
沙迪亞

+0

您的'@ Before'方法正在運行嗎? – 2013-05-12 08:20:03

+0

是的,我把一個斷點,並確認@Before方法正在運行。 – Sathya 2013-05-12 09:14:45

回答

2

,以模擬的電子郵件中,auth域也需要被嘲笑,只需添加

.setEnvAuthDomain("example.com"); 

到你的助手初始化或@Before方法後INITIALISE它將正常工作。

希望它有幫助

+0

非常感謝。這工作。 – Sathya 2013-05-12 21:57:47